From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2122) id DAF293858414; Fri, 10 Mar 2023 13:54:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DAF293858414 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678456480; bh=yHghJevbkJrNjVkVfIKAVxQnRV1HqQv6EAw4URU8Bak=; h=From:To:Subject:Date:From; b=lqMzzkfD2yuqNG4L0ssglDwcz0U9AawBLGyQAAgP+VMD2EjIhnO6Gg/mVzorpbCEr GS/HKAzyTBHV5bnhTkpBdZLqiXEYHiJnNiirT1oZzhQXlzDHo+KUgjlN+dZytUSC03 F3bEc6S59pPPtlx0pEUS5oI4NzYjhW2c1J4QIJFs= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jason Merrill To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-6582] c++: class NTTP and nested anon union [PR108566] X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/heads/trunk X-Git-Oldrev: c4fd232f9843bb800548a906653aeb0723cdb411 X-Git-Newrev: e1c8cf9006bd278e969ab7ed35178067ce128f32 Message-Id: <20230310135440.DAF293858414@sourceware.org> Date: Fri, 10 Mar 2023 13:54:40 +0000 (GMT) List-Id: https://gcc.gnu.org/g:e1c8cf9006bd278e969ab7ed35178067ce128f32 commit r13-6582-ge1c8cf9006bd278e969ab7ed35178067ce128f32 Author: Jason Merrill Date: Thu Mar 9 23:33:43 2023 -0500 c++: class NTTP and nested anon union [PR108566] We were failing to come up with the name for the anonymous union. It seems like unfortunate redundancy, but the ABI does say that the name of an anonymous union is its first named member. PR c++/108566 gcc/cp/ChangeLog: * mangle.cc (anon_aggr_naming_decl): New. (write_unqualified_name): Use it. gcc/testsuite/ChangeLog: * g++.dg/abi/anon6.C: New test. Diff: --- gcc/cp/mangle.cc | 27 ++++++++++++++++++++++++++- gcc/testsuite/g++.dg/abi/anon6.C | 19 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/gcc/cp/mangle.cc b/gcc/cp/mangle.cc index 242b3f31cba..a235f23459d 100644 --- a/gcc/cp/mangle.cc +++ b/gcc/cp/mangle.cc @@ -1389,6 +1389,28 @@ find_decomp_unqualified_name (tree decl, size_t *len) return p; } +/* "For the purposes of mangling, the name of an anonymous union is considered + to be the name of the first named data member found by a pre-order, + depth-first, declaration-order walk of the data members of the anonymous + union. If there is no such data member (i.e., if all of the data members in + the union are unnamed), then there is no way for a program to refer to the + anonymous union, and there is therefore no need to mangle its name." */ + +static tree +anon_aggr_naming_decl (tree type) +{ + tree field = next_aggregate_field (TYPE_FIELDS (type)); + for (; field; field = next_aggregate_field (DECL_CHAIN (field))) + { + if (DECL_NAME (field)) + return field; + if (ANON_AGGR_TYPE_P (TREE_TYPE (field))) + if (tree sub = anon_aggr_naming_decl (TREE_TYPE (field))) + return sub; + } + return NULL_TREE; +} + /* We don't need to handle thunks, vtables, or VTTs here. Those are mangled through special entry points. @@ -1432,7 +1454,10 @@ write_unqualified_name (tree decl) bool found = false; - if (DECL_NAME (decl) == NULL_TREE) + if (DECL_NAME (decl) == NULL_TREE + && ANON_AGGR_TYPE_P (TREE_TYPE (decl))) + decl = anon_aggr_naming_decl (TREE_TYPE (decl)); + else if (DECL_NAME (decl) == NULL_TREE) { found = true; gcc_assert (DECL_ASSEMBLER_NAME_SET_P (decl)); diff --git a/gcc/testsuite/g++.dg/abi/anon6.C b/gcc/testsuite/g++.dg/abi/anon6.C new file mode 100644 index 00000000000..7be0b0bbdb7 --- /dev/null +++ b/gcc/testsuite/g++.dg/abi/anon6.C @@ -0,0 +1,19 @@ +// PR c++/108566 +// { dg-do compile { target c++20 } } + +template +struct wrapper1 { + union { + union { + T RightName; + }; + }; +}; + +template void dummy(){} + +void uses() { + dummy{123.0}>(); +} + +// { dg-final { scan-assembler "_Z5dummyIXtl8wrapper1IdEtlNS1_Ut_Edi9RightNametlNS2_Ut_Edi9RightNameLd405ec00000000000EEEEEEvv" } }