From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 8F4423858C83; Tue, 16 May 2023 16:16:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8F4423858C83 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684253794; bh=TwNRvucHo3Z3iT3LipMjdSVww95aMjXhYob9I1CP2kc=; h=From:To:Subject:Date:From; b=Q2zr8b0pvf8OZuzgYZTBj7itmgTFQ9MJJKiOx2j8kjCWsYJoyQaGMTlVyYf9i5Swr j3p0p0gJh/TYfQzGX066A84oKH666HH/+qdsQ24wH26uFq44ruKWHSnVNbzjmISnXw ZznfmGCHJvOl6NJp72CcxG8RxPBjQN99+EIK9m+M= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r11-10777] libstdc++: Fix src/c++17/memory_resource for H8 targets [PR107801] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: 047c0fae82ca1458339e7e9724d125d30b685898 X-Git-Newrev: 23e12322bc03065557d9c0ee238b5b8d7b605c02 Message-Id: <20230516161634.8F4423858C83@sourceware.org> Date: Tue, 16 May 2023 16:16:34 +0000 (GMT) List-Id: https://gcc.gnu.org/g:23e12322bc03065557d9c0ee238b5b8d7b605c02 commit r11-10777-g23e12322bc03065557d9c0ee238b5b8d7b605c02 Author: Jonathan Wakely Date: Mon Nov 28 13:28:53 2022 +0000 libstdc++: Fix src/c++17/memory_resource for H8 targets [PR107801] This fixes compilation failures for H8 multilibs. For the normal multilib (ILP16L32?), the chunk struct does not have the expected size, because uint32_t is type long and has alignment 4 (by default). This forces sizeof(chunk) to be 12 instead of the expected 10. We can fix that by using bitset::size_type instead of uint32_t, so that we only use a 16-bit size when size_t and pointers are 16-bit types. For the IL32P16 multilibs that use -mint32, int is wider than size_t and so arithmetic expressions involving size_t promote to int. This means we need some explicit casts back to size_t. libstdc++-v3/ChangeLog: PR libstdc++/107801 * src/c++17/memory_resource.cc (chunk::_M_bytes): Change type from uint32_t to bitset::size_type. Adjust static assertion. (__pool_resource::_Pool::replenish): Cast to size_t after multiplication instead of before. (__pool_resource::_M_alloc_pools): Ensure both arguments to std::max have type size_t. (cherry picked from commit 75e562d2c4303d3918be9d1563284b0c580c5e45) Diff: --- libstdc++-v3/src/c++17/memory_resource.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libstdc++-v3/src/c++17/memory_resource.cc b/libstdc++-v3/src/c++17/memory_resource.cc index 154e334ba14..9c2aef8e520 100644 --- a/libstdc++-v3/src/c++17/memory_resource.cc +++ b/libstdc++-v3/src/c++17/memory_resource.cc @@ -502,7 +502,7 @@ namespace pmr } // Allocated size of chunk: - uint32_t _M_bytes = 0; + bitset::size_type _M_bytes = 0; // Start of allocated chunk: std::byte* _M_p = nullptr; @@ -576,7 +576,7 @@ namespace pmr // For 16-bit pointers it's five pointers (10 bytes). // TODO pad 64-bit to 4*sizeof(void*) to avoid splitting across cache lines? static_assert(sizeof(chunk) - == sizeof(bitset::size_type) + sizeof(uint32_t) + 2 * sizeof(void*)); + == 2 * sizeof(bitset::size_type) + 2 * sizeof(void*)); // An oversized allocation that doesn't fit in a pool. struct big_block @@ -731,7 +731,7 @@ namespace pmr _M_blocks_per_chunk = std::min({ max_blocks, __opts.max_blocks_per_chunk, - (size_t)_M_blocks_per_chunk * 2 + size_t(_M_blocks_per_chunk * 2) }); } } @@ -1054,7 +1054,8 @@ namespace pmr // Decide on initial number of blocks per chunk. // At least 16 blocks per chunk seems reasonable, // more for smaller blocks: - size_t blocks_per_chunk = std::max(size_t(16), 1024 / block_size); + size_t blocks_per_chunk = 1024 / block_size; + blocks_per_chunk = std::max(size_t(16), blocks_per_chunk); // But don't exceed the requested max_blocks_per_chunk: blocks_per_chunk = std::min(blocks_per_chunk, _M_opts.max_blocks_per_chunk);