From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 128964 invoked by alias); 11 Apr 2019 19:58:18 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 128949 invoked by uid 89); 11 Apr 2019 19:58:18 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-14.7 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=Increase, 1827, multiples, somewhere X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 11 Apr 2019 19:58:16 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A8F673087920; Thu, 11 Apr 2019 19:58:15 +0000 (UTC) Received: from localhost (unknown [10.33.36.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5C94261998; Thu, 11 Apr 2019 19:58:15 +0000 (UTC) Date: Thu, 11 Apr 2019 20:16:00 -0000 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] PR libstdc++/90046 fix build failure on epiphany-elf Message-ID: <20190411195814.GA3289@redhat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="9jxsPFA5p3P2qPhR" Content-Disposition: inline X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.11.3 (2019-02-01) X-SW-Source: 2019-04/txt/msg00460.txt.bz2 --9jxsPFA5p3P2qPhR Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline Content-length: 918 The epiphany-elf target aligns structs to 8 bytes, which causes the static_assert(alignof(_Chunk) == 1) to fail. Instead of requiring _Chunks to be positionable at any alignment, ensure new buffers are aligned to alignof(_Chunk). Because the buffer size is a power of two, we know that both the buffer size and sizeof(_Chunk) are multiples of alignof(_Chunk). So is p is aligned to alignof(_Chunk) then so is (p + size - sizeof(_Chunk)). So just ensure the new buffer is aligned to at least alignof(_Chunk), which should already be true because the caller requests at least alignof(max_align_t). PR libstdc++/90046 * src/c++17/memory_resource.cc (monotonic_buffer_resource::_Chunk::allocate): Increase alignment if needed to allow placing a _Chunk at the end of the buffer. (monotonic_buffer_resource::_M_new_buffer): Remove static_assert. Tested x86_64-linux, bootstrapped epiphany-elf, committed to trunk./ --9jxsPFA5p3P2qPhR Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="patch.txt" Content-length: 2630 commit 8af70056b079035bfb5a6a3a9df4b10194b025cf Author: Jonathan Wakely Date: Thu Apr 11 20:32:40 2019 +0100 PR libstdc++/90046 fix build failure on epiphany-elf The epiphany-elf target aligns structs to 8 bytes, which causes the static_assert(alignof(_Chunk) == 1) to fail. Instead of requiring _Chunks to be positionable at any alignment, ensure new buffers are aligned to alignof(_Chunk). Because the buffer size is a power of two, we know that both the buffer size and sizeof(_Chunk) are multiples of alignof(_Chunk). So is p is aligned to alignof(_Chunk) then so is (p + size - sizeof(_Chunk)). So just ensure the new buffer is aligned to at least alignof(_Chunk), which should already be true because the caller requests at least alignof(max_align_t). PR libstdc++/90046 * src/c++17/memory_resource.cc (monotonic_buffer_resource::_Chunk::allocate): Increase alignment if needed to allow placing a _Chunk at the end of the buffer. (monotonic_buffer_resource::_M_new_buffer): Remove static_assert. diff --git a/libstdc++-v3/src/c++17/memory_resource.cc b/libstdc++-v3/src/c++17/memory_resource.cc index cd11bf5875c..b6698011f5c 100644 --- a/libstdc++-v3/src/c++17/memory_resource.cc +++ b/libstdc++-v3/src/c++17/memory_resource.cc @@ -182,7 +182,21 @@ namespace pmr _Chunk*& __head) { __size = std::__ceil2(__size + sizeof(_Chunk)); + + if constexpr (alignof(_Chunk) > 1) + { + // PR libstdc++/90046 + // For targets like epiphany-elf where alignof(_Chunk) != 1 + // ensure that the last sizeof(_Chunk) bytes in the buffer + // are suitably-aligned for a _Chunk. + // This should be unnecessary, because the caller already + // passes in max(__align, alignof(max_align_t)). + if (__align < alignof(_Chunk)) + __align = alignof(_Chunk); + } + void* __p = __r->allocate(__size, __align); + // Add a chunk defined by (__p, __size, __align) to linked list __head. void* const __back = (char*)__p + __size - sizeof(_Chunk); __head = ::new(__back) _Chunk(__size, __align, __head); @@ -231,9 +245,6 @@ namespace pmr void monotonic_buffer_resource::_M_new_buffer(size_t bytes, size_t alignment) { - // Need to check this somewhere, so put it here: - static_assert(alignof(monotonic_buffer_resource::_Chunk) == 1); - const size_t n = std::max(bytes, _M_next_bufsiz); const size_t m = std::max(alignment, alignof(std::max_align_t)); auto [p, size] = _Chunk::allocate(_M_upstream, n, m, _M_head); --9jxsPFA5p3P2qPhR--