From patchwork Wed Oct 30 21:24:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 2004385 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=cc4FCjLd; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4Xf0Z669FMz1xwK for ; Thu, 31 Oct 2024 08:26:54 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CAB5B3857820 for ; Wed, 30 Oct 2024 21:26:52 +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 ESMTP id 5F6D43858D33 for ; Wed, 30 Oct 2024 21:26:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5F6D43858D33 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 5F6D43858D33 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=1730323594; cv=none; b=QWyjeAt2pARibuN/a/ZuEtGsoYWY2SqKcRLqDjrXIoiCLARcTOEJWqwIbVsXhJQ1oKlIXUhnmxMJ+Z40IHUi5LqtEj5fG7pru8tNg+aoFvqEQOtBE5tR9mH+hq9ZEXIYlwG6j80r/jXA8Q2QsXSIqCsCkMzlTJNphdb/x7FvVrs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730323594; c=relaxed/simple; bh=i75Z/eFoqDbmTCYgjMaB+WUXuwrn8zFEhC3MjvxjFg8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=L2+yH1oUkzCdlOgQpNyVD6aMN15rOCc+xY3HWfEo57PNWZvPJbKiVVaRtS2KZooV1aqplrQiQx8uxWCMbK6B48cS8bI/e7K/7Yf45dki6fiEws4WvizPkBvCoGoNvZwjqFN/0bIsbWOiHyRaVgB1nejKfcSwHOxXI6vW8D43y90= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730323592; 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=NGDdCWIawDd6aM2wqHdd0gzUf23+oohWefBq94oCIug=; b=cc4FCjLdjbbh5/eTLRQRDMH2cR8Y8ZxFUgmRxAZ/RWIUBLBauBQfDQwkj0iSerdMXOMaPR k87+G+AtGyJnljLE5x2mg5sgd2LvhOOnhpMKjwq12f6HrxsTCDakPHM+caookYrlbIl5io TeJ/khwA4m0IjS/iHAEsAINjAT6tc3w= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-553-HFiNg-VTOrS2ULBW95quOQ-1; Wed, 30 Oct 2024 17:26:30 -0400 X-MC-Unique: HFiNg-VTOrS2ULBW95quOQ-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3A1FC19560B7; Wed, 30 Oct 2024 21:26:29 +0000 (UTC) Received: from localhost (unknown [10.42.28.115]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 72D001955F40; Wed, 30 Oct 2024 21:26:28 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] libstdc++: Add align_alloc attribute to aligned operator new Date: Wed, 30 Oct 2024 21:24:05 +0000 Message-ID: <20241030212626.1323680-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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 The aligned versions of operator new should use the align_alloc attribute to help the compiler. PR c++/86878 requests that the compiler would use the attribute to warn about invalid attributes, so an XFAILed test is added for that. libstdc++-v3/ChangeLog: * libsupc++/new (operator new): Add attribute align_alloc(2) to overloads taking a std::align_val_t argument. * testsuite/18_support/new_aligned_warn.cc: New test. --- I think this makes sense, but maybe there's some property of the attribute that means this isn't a good idea? I think the compiler can use the value of align_val_t even though it's a scoped enumeration type. Tested x86_64-linux. libstdc++-v3/libsupc++/new | 6 +++--- .../testsuite/18_support/new_aligned_warn.cc | 13 +++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 libstdc++-v3/testsuite/18_support/new_aligned_warn.cc diff --git a/libstdc++-v3/libsupc++/new b/libstdc++-v3/libsupc++/new index e9a3d9b49a3..4345030071b 100644 --- a/libstdc++-v3/libsupc++/new +++ b/libstdc++-v3/libsupc++/new @@ -167,7 +167,7 @@ void operator delete[](void*, const std::nothrow_t&) #if __cpp_aligned_new _GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t) _GLIBCXX_TXN_SAFE - __attribute__((__externally_visible__, __alloc_size__ (1), __malloc__)); + __attribute__((__externally_visible__, __alloc_size__ (1), __alloc_align__ (2), __malloc__)); _GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t, const std::nothrow_t&) _GLIBCXX_TXN_SAFE _GLIBCXX_USE_NOEXCEPT __attribute__((__externally_visible__, __alloc_size__ (1), __malloc__)); @@ -178,10 +178,10 @@ void operator delete(void*, std::align_val_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT __attribute__((__externally_visible__)); _GLIBCXX_NODISCARD void* operator new[](std::size_t, std::align_val_t) _GLIBCXX_TXN_SAFE - __attribute__((__externally_visible__, __alloc_size__ (1), __malloc__)); + __attribute__((__externally_visible__, __alloc_size__ (1), __alloc_align__ (2), __malloc__)); _GLIBCXX_NODISCARD void* operator new[](std::size_t, std::align_val_t, const std::nothrow_t&) _GLIBCXX_TXN_SAFE - _GLIBCXX_USE_NOEXCEPT __attribute__((__externally_visible__, __alloc_size__ (1), __malloc__)); + _GLIBCXX_USE_NOEXCEPT __attribute__((__externally_visible__, __alloc_size__ (1), __alloc_align__ (2), __malloc__)); void operator delete[](void*, std::align_val_t) _GLIBCXX_TXN_SAFE _GLIBCXX_USE_NOEXCEPT __attribute__((__externally_visible__)); void operator delete[](void*, std::align_val_t, const std::nothrow_t&) diff --git a/libstdc++-v3/testsuite/18_support/new_aligned_warn.cc b/libstdc++-v3/testsuite/18_support/new_aligned_warn.cc new file mode 100644 index 00000000000..e9d374abe31 --- /dev/null +++ b/libstdc++-v3/testsuite/18_support/new_aligned_warn.cc @@ -0,0 +1,13 @@ +// { dg-options "-Wattributes" } +// { dg-do compile { target c++17 } } + +#include + +int main() +{ + // PR c++/86878 has a patch to make these warn. + (void) operator new(1, std::align_val_t(3)); // { dg-warning "power of two" "" { xfail *-*-* } } + (void) operator new[](1, std::align_val_t(10)); // { dg-warning "power of two" "" { xfail *-*-* } } + (void) operator new(1, std::align_val_t(0), std::nothrow_t()); // { dg-warning "power of two" "" { xfail *-*-* } } + (void) operator new[](1, std::align_val_t(-1), std::nothrow_t()); // { dg-warning "power of two" "" { xfail *-*-* } } +}