From patchwork Thu Sep 5 12:47:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1981237 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=PukWGcWk; 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 4WzzgC5hQQz1yXY for ; Thu, 5 Sep 2024 22:48:23 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B5E373865C22 for ; Thu, 5 Sep 2024 12:48:21 +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.133.124]) by sourceware.org (Postfix) with ESMTP id ECAAD385EC1D for ; Thu, 5 Sep 2024 12:47:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ECAAD385EC1D 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 ECAAD385EC1D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725540473; cv=none; b=jDTHzisSCdYa0H5uOKMDsSAFyi8+ZNsYjDZuIH+SGQby5lqJ914ji8+FKFyzahRoerd6or44SMTGPRFOhUQxqiXcyYZJuiian3F5+13Uho/2qwQFmEbQXA3mxtOfV40/cg78uCBtCTUqUai+IfqSpVIiro79BBjq+gO7gILFiNk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725540473; c=relaxed/simple; bh=0nP80mcGXJuHLOn0Jz+Y6k9VWnfSUnAynSVW+hI9a0w=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=UIREfJdEXzeDF3Pm84BPUtDa2yxBJNROo+6rYzOveiKzQmisqjKdmCPQJky/CFhAUtYNBM1AoBmBGjaKltJ2/d1shCiot8yxdIuI7c3kajiEON3WTJ63TOYrQ53JVhvnFSeD5pp7ul9P2vDF8OkidkF0ky2LnI4xEA6Cs3hiImQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725540469; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=UDEaUtD2Rf5F+8SGiWvaADH5Tz4RLH5G6cT0QZyW46Y=; b=PukWGcWk7yjz/lSHOZT+rGfdp6/O91Vj9VhUtl1SzPXCeaUk4WGUsPduKt0vtRDQFwQPZP awOQVX/FsTS1LfF3r5XHWAIYmJNRaUjH5YkOffD4sKsrf4pFbx7OwDKafHGM4fY6kws2Gp zCkeYWMSJwEb3b6ZZqvkeESnDff3F80= Received: from mx-prod-mc-05.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-56-JrXxCeLEPrqZPbYgGf8TFQ-1; Thu, 05 Sep 2024 08:47:47 -0400 X-MC-Unique: JrXxCeLEPrqZPbYgGf8TFQ-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.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 mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B587C1955F07 for ; Thu, 5 Sep 2024 12:47:46 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.29]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C550730001AB; Thu, 5 Sep 2024 12:47:40 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 485ClcOm1865081 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 5 Sep 2024 14:47:38 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 485Clcus1865080; Thu, 5 Sep 2024 14:47:38 +0200 Date: Thu, 5 Sep 2024 14:47:37 +0200 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: c++: Add no_unique_address attribute further test coverage [PR110345] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no 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: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Hi! Another non-problematic attribute. Tested on x86_64-linux and i686-linux, ok for trunk? 2024-09-05 Jakub Jelinek PR c++/110345 * g++.dg/cpp0x/attr-no_unique_address1.C: New test. Jakub --- gcc/testsuite/g++.dg/cpp0x/attr-no_unique_address1.C.jj 2024-09-05 14:01:00.396886959 +0200 +++ gcc/testsuite/g++.dg/cpp0x/attr-no_unique_address1.C 2024-09-05 14:11:04.710883438 +0200 @@ -0,0 +1,151 @@ +// C++ 26 P2552R3 - On the ignorability of standard attributes +// { dg-do compile { target c++11 } } + +int arr[2]; +struct S { int a, b; }; +S arr2[2]; + +struct S2 { + [[no_unique_address]] struct {} a; + [[no_unique_address ("foobar")]] struct {} b; // { dg-error "'no_unique_address' attribute does not take any arguments" } + [[no_unique_address (0)]] struct {} c; // { dg-error "'no_unique_address' attribute does not take any arguments" } + struct {} d [[no_unique_address]]; +}; + +void +foo (int n) +{ + auto a = [] [[no_unique_address]] () { }; // { dg-warning "'no_unique_address' attribute can only be applied to non-static data members" } + auto b = [] constexpr [[no_unique_address]] {}; // { dg-warning "'no_unique_address' attribute does not apply to types" } + // { dg-error "parameter declaration before lambda declaration specifiers only optional with" "" { target c++20_down } .-1 } + // { dg-error "'constexpr' lambda only available with" "" { target c++14_down } .-2 } + auto c = [] noexcept [[no_unique_address]] {}; // { dg-warning "'no_unique_address' attribute does not apply to types" } + // { dg-error "parameter declaration before lambda exception specification only optional with" "" { target c++20_down } .-1 } + auto d = [] () [[no_unique_address]] {}; // { dg-warning "'no_unique_address' attribute does not apply to types" } + auto e = new int [n] [[no_unique_address]]; // { dg-warning "attributes ignored on outermost array type in new expression" } + auto e2 = new int [n] [[no_unique_address]] [42]; // { dg-warning "attributes ignored on outermost array type in new expression" } + auto f = new int [n][42] [[no_unique_address]]; // { dg-warning "'no_unique_address' attribute does not apply to types" } + [[no_unique_address]]; // { dg-warning "attributes at the beginning of statement are ignored" } + [[no_unique_address]] {} // { dg-warning "attributes at the beginning of statement are ignored" } + [[no_unique_address]] if (true) {} // { dg-warning "attributes at the beginning of statement are ignored" } + [[no_unique_address]] while (false) {} // { dg-warning "attributes at the beginning of statement are ignored" } + [[no_unique_address]] goto lab; // { dg-warning "attributes at the beginning of statement are ignored" } + [[no_unique_address]] lab:; // { dg-warning "'no_unique_address' attribute can only be applied to non-static data members" } + [[no_unique_address]] try {} catch (int) {} // { dg-warning "attributes at the beginning of statement are ignored" } + if ([[no_unique_address]] int x = 0) {} // { dg-warning "'no_unique_address' attribute can only be applied to non-static data members" } + switch (n) + { + [[no_unique_address]] case 1: // { dg-warning "'no_unique_address' attribute can only be applied to non-static data members" } + [[no_unique_address]] break; // { dg-warning "attributes at the beginning of statement are ignored" } + [[no_unique_address]] default: // { dg-warning "'no_unique_address' attribute can only be applied to non-static data members" } + break; + } + for ([[no_unique_address]] auto a : arr) {} // { dg-warning "'no_unique_address' attribute can only be applied to non-static data members" } + for ([[no_unique_address]] auto [a, b] : arr2) {} // { dg-warning "'no_unique_address' attribute can only be applied to non-static data members" } + // { dg-error "structured bindings only available with" "" { target c++14_down } .-1 } + [[no_unique_address]] asm (""); // { dg-warning "attributes ignored on 'asm' declaration" } + try {} catch ([[no_unique_address]] int x) {} // { dg-warning "'no_unique_address' attribute can only be applied to non-static data members" } + try {} catch ([[no_unique_address]] int) {} // { dg-warning "'no_unique_address' attribute can only be applied to non-static data members" } + try {} catch (int [[no_unique_address]] x) {} // { dg-warning "attribute ignored" } + try {} catch (int [[no_unique_address]]) {} // { dg-warning "attribute ignored" } + try {} catch (int x [[no_unique_address]]) {} // { dg-warning "'no_unique_address' attribute can only be applied to non-static data members" } +} + +[[no_unique_address]] int bar (); // { dg-warning "'no_unique_address' attribute can only be applied to non-static data members" } +using foobar [[no_unique_address]] = int; // { dg-warning "'no_unique_address' attribute can only be applied to non-static data members" } +[[no_unique_address]] int a; // { dg-warning "'no_unique_address' attribute can only be applied to non-static data members" } +[[no_unique_address]] auto [b, c] = arr; // { dg-warning "'no_unique_address' attribute can only be applied to non-static data members" } + // { dg-error "structured bindings only available with" "" { target c++14_down } .-1 } +[[no_unique_address]]; // { dg-warning "attribute ignored" } +inline [[no_unique_address]] void baz () {} // { dg-warning "attribute ignored" } + // { dg-error "standard attributes in middle of decl-specifiers" "" { target *-*-* } .-1 } +constexpr [[no_unique_address]] int qux () { return 0; } // { dg-warning "attribute ignored" } + // { dg-error "standard attributes in middle of decl-specifiers" "" { target *-*-* } .-1 } +int [[no_unique_address]] d; // { dg-warning "attribute ignored" } +int const [[no_unique_address]] e = 1; // { dg-warning "attribute ignored" } +struct A {} [[no_unique_address]]; // { dg-warning "attribute ignored in declaration of 'struct A'" } +struct A [[no_unique_address]]; // { dg-warning "attribute ignored" } +struct A [[no_unique_address]] a1; // { dg-warning "attribute ignored" } +A [[no_unique_address]] a2; // { dg-warning "attribute ignored" } +enum B { B0 } [[no_unique_address]]; // { dg-warning "attribute ignored in declaration of 'enum B'" } +enum B [[no_unique_address]]; // { dg-warning "attribute ignored" } +enum B [[no_unique_address]] b1; // { dg-warning "attribute ignored" } +B [[no_unique_address]] b2; // { dg-warning "attribute ignored" } +struct [[no_unique_address]] C {}; // { dg-warning "'no_unique_address' attribute does not apply to types" } +int f [[no_unique_address]]; // { dg-warning "'no_unique_address' attribute can only be applied to non-static data members" } +int g[2] [[no_unique_address]]; // { dg-warning "'no_unique_address' attribute does not apply to types" } +int g2 [[no_unique_address]] [2]; // { dg-warning "'no_unique_address' attribute can only be applied to non-static data members" } +int corge () [[no_unique_address]]; // { dg-warning "'no_unique_address' attribute does not apply to types" } +int *[[no_unique_address]] h; // { dg-warning "'no_unique_address' attribute does not apply to types" } +int & [[no_unique_address]] i = f; // { dg-warning "'no_unique_address' attribute does not apply to types" } +int && [[no_unique_address]] j = 0; // { dg-warning "'no_unique_address' attribute does not apply to types" } +int S::* [[no_unique_address]] k; // { dg-warning "'no_unique_address' attribute does not apply to types" } +auto l = sizeof (int [2] [[no_unique_address]]); // { dg-warning "'no_unique_address' attribute does not apply to types" } +int freddy ([[no_unique_address]] int a, // { dg-warning "'no_unique_address' attribute can only be applied to non-static data members" } + [[no_unique_address]] int, // { dg-warning "'no_unique_address' attribute can only be applied to non-static data members" } + [[no_unique_address]] int c = 0, // { dg-warning "'no_unique_address' attribute can only be applied to non-static data members" } + [[no_unique_address]] int = 0); // { dg-warning "'no_unique_address' attribute can only be applied to non-static data members" } +void +corge ([[no_unique_address]] int a, // { dg-warning "'no_unique_address' attribute can only be applied to non-static data members" } + [[no_unique_address]] int, // { dg-warning "'no_unique_address' attribute can only be applied to non-static data members" } + [[no_unique_address]] int c = 0, // { dg-warning "'no_unique_address' attribute can only be applied to non-static data members" } + [[no_unique_address]] int = 0) // { dg-warning "'no_unique_address' attribute can only be applied to non-static data members" } +{ +} +[[no_unique_address]] void +garply () // { dg-warning "'no_unique_address' attribute can only be applied to non-static data members" } +{ +} +int grault (int [[no_unique_address]] a, // { dg-warning "attribute ignored" } + int [[no_unique_address]], // { dg-warning "attribute ignored" } + int [[no_unique_address]] c = 0, // { dg-warning "attribute ignored" } + int [[no_unique_address]] = 0); // { dg-warning "attribute ignored" } +void +waldo (int [[no_unique_address]] a, // { dg-warning "attribute ignored" } + int [[no_unique_address]], // { dg-warning "attribute ignored" } + int [[no_unique_address]] c = 0, // { dg-warning "attribute ignored" } + int [[no_unique_address]] = 0) // { dg-warning "attribute ignored" } +{ +} +int plugh (int a [[no_unique_address]], // { dg-warning "'no_unique_address' attribute can only be applied to non-static data members" } + int b [[no_unique_address]] = 0); // { dg-warning "'no_unique_address' attribute can only be applied to non-static data members" } +void +thud (int a [[no_unique_address]], // { dg-warning "'no_unique_address' attribute can only be applied to non-static data members" } + int b [[no_unique_address]] = 0) // { dg-warning "'no_unique_address' attribute can only be applied to non-static data members" } +{ +} +enum [[no_unique_address]] D { D0 }; // { dg-warning "'no_unique_address' attribute does not apply to types" } +enum class [[no_unique_address]] E { E0 }; // { dg-warning "'no_unique_address' attribute does not apply to types" } +enum F {}; +enum [[no_unique_address]] F; // { dg-warning "'no_unique_address' attribute does not apply to types" } +enum G { + G0 [[no_unique_address]], // { dg-warning "'no_unique_address' attribute can only be applied to non-static data members" } + G1 [[no_unique_address]] = 2 // { dg-warning "'no_unique_address' attribute can only be applied to non-static data members" } +}; +namespace [[no_unique_address]] H { using H0 = int; } // { dg-warning "'no_unique_address' attribute directive ignored" } +namespace [[no_unique_address]] {} // { dg-warning "'no_unique_address' attribute directive ignored" } +[[no_unique_address]] using namespace H; // { dg-warning "'no_unique_address' attribute directive ignored" } +struct [[no_unique_address]] I // { dg-warning "'no_unique_address' attribute does not apply to types" } +{ + [[no_unique_address]]; // { dg-error "declaration does not declare anything" } + [[no_unique_address]] int i; + [[no_unique_address]] int foo (); // { dg-warning "'no_unique_address' attribute can only be applied to non-static data members" } + [[no_unique_address]] int bar () { return 1; } // { dg-warning "'no_unique_address' attribute can only be applied to non-static data members" } + [[no_unique_address]] int : 0; // { dg-warning "'no_unique_address' attribute cannot be applied to a bit-field" } + [[no_unique_address]] int i2 : 5; // { dg-warning "'no_unique_address' attribute cannot be applied to a bit-field" } + [[no_unique_address]] static int i3; // { dg-warning "'no_unique_address' attribute can only be applied to non-static data members" } + static int i4; +}; +[[no_unique_address]] int I::i4 = 0; // { dg-warning "'no_unique_address' attribute can only be applied to non-static data members" } +struct J : [[no_unique_address]] C {}; // { dg-warning "attributes on base specifiers are ignored" } +#if __cpp_concepts >= 201907L +template +concept K [[no_unique_address]] = requires { true; }; // { dg-warning "'no_unique_address' attribute can only be applied to non-static data members" "" { target c++20 } } +#endif +typedef int L [[no_unique_address]]; // { dg-warning "'no_unique_address' attribute can only be applied to non-static data members" } +template +struct M {}; +template <> +struct [[no_unique_address]] M { int m; }; // { dg-warning "'no_unique_address' attribute does not apply to types" } +typedef int N[2] [[no_unique_address]]; // { dg-warning "'no_unique_address' attribute does not apply to types" } +typedef int O [[no_unique_address]] [2]; // { dg-warning "'no_unique_address' attribute can only be applied to non-static data members" }