From patchwork Fri Mar 10 13:54:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 66210 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 1E6663858025 for ; Fri, 10 Mar 2023 13:54:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1E6663858025 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678456496; bh=/7dEt8WDLOrmXKi8KP4Lg/eV/bN/pruX9yIkBxvIcMk=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=scKJO9cuOvtYJposHS+1eGeWgCwkQAw6P08mRtx4YjGJ9xx5z66rr45UQJXhaZ3Zd ZNF/ib6kHYEScMVCY9hX43rKZIdrhnosGw6ohNAYQWePW7eNKB+50l0QQBp7PubMCL U3xZFRH9I4RAQbLwQZA3q2z+uZ0bvnap8Kl5ufrs= 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 ESMTPS id AC1603858D32 for ; Fri, 10 Mar 2023 13:54:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AC1603858D32 Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-194-pNtTsz_wN_Sr6cNZb3-r0A-1; Fri, 10 Mar 2023 08:54:26 -0500 X-MC-Unique: pNtTsz_wN_Sr6cNZb3-r0A-1 Received: by mail-qt1-f197.google.com with SMTP id br8-20020a05622a1e0800b003c0189c37e1so2904704qtb.18 for ; Fri, 10 Mar 2023 05:54:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678456465; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/7dEt8WDLOrmXKi8KP4Lg/eV/bN/pruX9yIkBxvIcMk=; b=3r6apET2NzvXPMuHyTzvhMSeiW64xv9MjoFHQD+sIJbWmGO1IJtHhXvQYrO2Ua85YN FEK0uXXrFOBqvOZEHrhMXp77w6HzyS7uVqpogcUSqPtf7LmaUbfIQoAXQartNOiZXa9b Wh22b83ho4321FfXP1Z29Zx7i4UJiom4cz8GYleskoHWQ9wICsyXTC+Q3Rmrxo6XElCr Zv6Fm6gSoxQ8n6pb4OtIPew9DlxXow/eyk2eNmZsAEZQZSgJkrM5gEZ7eT202DqSeKK0 nyhGTKGRXIKb6QIzsBrpt5rcJLp6fRbjrEzsVuBJxNTL5AMnZGzAVTzZhW+equ1XHros m1jw== X-Gm-Message-State: AO0yUKWGfxaTNeRW7Vnn3cLmABwhRjZP3CRVuLGIq9eycoK4aslSELnC x+GJmIy7dWryOchrUZbnmo14W8TMnCCDFfMBB8SKSwo6UyBoauEVOwQp+NZKwZ1HPxnYborvXlr pQ4c20d2FbewOE+vb5mEAJQP7HYkk2KfEyH8dO9HmgRHY9FK8MohBAE9nv60YUY1K+Tmirg+YuA == X-Received: by 2002:ac8:5f0d:0:b0:3bf:c423:c36d with SMTP id x13-20020ac85f0d000000b003bfc423c36dmr3757176qta.12.1678456465273; Fri, 10 Mar 2023 05:54:25 -0800 (PST) X-Google-Smtp-Source: AK7set8+9sHEt5Kozdl9jxocxVJaKToA1WF9h0p3SOCsEbNTsvwp5OXbuIFP3d/Wef0BIgaqYbzUlw== X-Received: by 2002:ac8:5f0d:0:b0:3bf:c423:c36d with SMTP id x13-20020ac85f0d000000b003bfc423c36dmr3757131qta.12.1678456464719; Fri, 10 Mar 2023 05:54:24 -0800 (PST) Received: from jason.com (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id d2-20020ac86142000000b003a81eef14efsm1422177qtm.45.2023.03.10.05.54.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Mar 2023 05:54:24 -0800 (PST) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: class NTTP and nested anon union [PR108566] Date: Fri, 10 Mar 2023 08:54:20 -0500 Message-Id: <20230310135420.2492295-1-jason@redhat.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.6 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=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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- 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. --- gcc/cp/mangle.cc | 27 ++++++++++++++++++++++++++- gcc/testsuite/g++.dg/abi/anon6.C | 19 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/abi/anon6.C base-commit: 2fc55f51f9953b451d6d6ddfae23379001e6ac95 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" } }