From patchwork Mon Nov 28 17:00:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 61177 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1C0DF3898505 for ; Mon, 28 Nov 2022 17:01:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1C0DF3898505 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669654895; bh=zBqzShC+qZs+BJQq0SR8QR9yJHuhqvGRukWfJHZYpbY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=jSCHQYsLGp30eiDXdPxojP0cwQq/JX3JvlHasO24lXk74qz57FvpcQ9le9eH6wZuV tefZv9WeE10yZLaHguHJ/ZGrwhTDaegcFfRrChCPhxO70wAQ4DXStgwwCFeGvt2FhX afbYbstHCKHPEA3kcUAXgEdJgLYuUfR2qltyKK8I= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 790FD38400A6 for ; Mon, 28 Nov 2022 17:00:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 790FD38400A6 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-215-zmEqCiYpPnCFZO9T-Gxdgg-1; Mon, 28 Nov 2022 12:00:33 -0500 X-MC-Unique: zmEqCiYpPnCFZO9T-Gxdgg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EFD43101A5BB; Mon, 28 Nov 2022 17:00:30 +0000 (UTC) Received: from localhost (unknown [10.33.36.137]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA5A9C15BA4; Mon, 28 Nov 2022 17:00:30 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Fix src/c++17/memory_resource for H8 targets [PR107801] Date: Mon, 28 Nov 2022 17:00:28 +0000 Message-Id: <20221128170028.61462-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Tested x86_64-linux, built on msp430-elf and h8300-elf. Pushed to trunk. -- >8 -- 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 I32LP16 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. --- 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 0bd94dbc6a7..a1854c55bd0 100644 --- a/libstdc++-v3/src/c++17/memory_resource.cc +++ b/libstdc++-v3/src/c++17/memory_resource.cc @@ -505,7 +505,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; @@ -579,7 +579,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 @@ -734,7 +734,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) }); } } @@ -1057,7 +1057,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);