From patchwork Wed May 22 22:30:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1938080 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=UrafeyX9; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Vl5cx0srPz2020 for ; Thu, 23 May 2024 08:31:27 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E6CBD3865C2B for ; Wed, 22 May 2024 22:31:25 +0000 (GMT) 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 428563865C13 for ; Wed, 22 May 2024 22:31:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 428563865C13 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 428563865C13 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716417065; cv=none; b=r11cpkSYZPRsJDWNBKtTnRHqqQF6IgX6CY4OU4tGOGqQ7oiXETbeWxPHF4N8pBbEVl+TAF3egaCStLwziviLup8upOMnmnfma/9yAsL9r/KMH/WtsjcNAUtnrm2CjMse4lMJbRElqoxKnt/RDI7CEsi1+Ugr/qPPucN6lSEgAwI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716417065; c=relaxed/simple; bh=D+g/SpLT/h3zs0EyOYWgkSHncAQyqEMzijkjJ3yLwro=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ZfgdIVZAL2mHWzsR8+beEznAcW4Mc5M3/EqhOhCnxYAiC+g7MWJDgkdDNPNvTVZUHWpovj/6aJUt0UThL79o9rn1SjUymvIWQ2AqRQEaUDiOLBAI9SDgKVsWNtyELxLcaPGUZLkTHu3yO4qMvrVYsQpMr6rfS7ww5lk7sNj/9+0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716417061; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=mENDyAc28y4VoCGDqT/DZXh7pFTQUUccDH0sy12pyjY=; b=UrafeyX9XhP/CAxaJYbwGWPpSIIoXItYFjQXEItrIJatA9SpOpxWH2tCPeds7ZTL+fp5rr 5Fui0LFBCWm3p2cRaA2mnXUU9sGq4j3HHYC54CQxVcv+gY3O79qyJ7JnBpBLrRAvsmGK2i Gf4rE+2oza2dLd4v7XD5UKaipEbifIg= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-463-gJy6r0TTMk6wDgP1EuPxXQ-1; Wed, 22 May 2024 18:31:00 -0400 X-MC-Unique: gJy6r0TTMk6wDgP1EuPxXQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0C8C3812296; Wed, 22 May 2024 22:31:00 +0000 (UTC) Received: from localhost (unknown [10.42.28.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id CFE9F2026D68; Wed, 22 May 2024 22:30:59 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Guard use of sized deallocation [PR114940] Date: Wed, 22 May 2024 23:30:45 +0100 Message-ID: <20240522223059.345584-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.9 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Tested x86_64-linux. Pushed to trunk. Backport needed too. -- >8 -- Clang does not enable -fsized-deallocation by default, which means it can't compile our and headers. Make the __cpp_lib_generator macro depend on the compiler-defined __cpp_sized_deallocation macro, and change to use unsized deallocation when __cpp_sized_deallocation isn't defined. libstdc++-v3/ChangeLog: PR libstdc++/114940 * include/bits/version.def (generator): Depend on __cpp_sized_deallocation. * include/bits/version.h: Regenerate. * include/std/stacktrace (_GLIBCXX_SIZED_DELETE): New macro. (basic_stacktrace::_Impl::_M_deallocate): Use it. --- libstdc++-v3/include/bits/version.def | 2 +- libstdc++-v3/include/bits/version.h | 2 +- libstdc++-v3/include/std/stacktrace | 13 +++++++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/libstdc++-v3/include/bits/version.def b/libstdc++-v3/include/bits/version.def index f0ba4f2bb3d..5cbc9d1a8d8 100644 --- a/libstdc++-v3/include/bits/version.def +++ b/libstdc++-v3/include/bits/version.def @@ -1651,7 +1651,7 @@ ftms = { values = { v = 202207; cxxmin = 23; - extra_cond = "__glibcxx_coroutine"; + extra_cond = "__glibcxx_coroutine && __cpp_sized_deallocation"; }; }; diff --git a/libstdc++-v3/include/bits/version.h b/libstdc++-v3/include/bits/version.h index f30f51dcedc..164ebed4983 100644 --- a/libstdc++-v3/include/bits/version.h +++ b/libstdc++-v3/include/bits/version.h @@ -1834,7 +1834,7 @@ #undef __glibcxx_want_forward_like #if !defined(__cpp_lib_generator) -# if (__cplusplus >= 202100L) && (__glibcxx_coroutine) +# if (__cplusplus >= 202100L) && (__glibcxx_coroutine && __cpp_sized_deallocation) # define __glibcxx_generator 202207L # if defined(__glibcxx_want_all) || defined(__glibcxx_want_generator) # define __cpp_lib_generator 202207L diff --git a/libstdc++-v3/include/std/stacktrace b/libstdc++-v3/include/std/stacktrace index d217d63af3b..962dbed7a41 100644 --- a/libstdc++-v3/include/std/stacktrace +++ b/libstdc++-v3/include/std/stacktrace @@ -551,6 +551,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #else # define _GLIBCXX_OPERATOR_NEW ::operator new # define _GLIBCXX_OPERATOR_DELETE ::operator delete +#endif + +#if __cpp_sized_deallocation +# define _GLIBCXX_SIZED_DELETE(T, p, n) \ + _GLIBCXX_OPERATOR_DELETE((p), (n) * sizeof(T)) +#else +# define _GLIBCXX_SIZED_DELETE(T, p, n) _GLIBCXX_OPERATOR_DELETE(p) #endif // Precondition: _M_frames == nullptr && __n != 0 @@ -592,8 +599,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION if (_M_capacity) { if constexpr (is_same_v>) - _GLIBCXX_OPERATOR_DELETE (static_cast(_M_frames), - _M_capacity * sizeof(value_type)); + _GLIBCXX_SIZED_DELETE(value_type, + static_cast(_M_frames), + _M_capacity); else __alloc.deallocate(_M_frames, _M_capacity); _M_frames = nullptr; @@ -601,6 +609,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } } +#undef _GLIBCXX_SIZED_DELETE #undef _GLIBCXX_OPERATOR_DELETE #undef _GLIBCXX_OPERATOR_NEW