From patchwork Tue Sep 10 18:06:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Martin X-Patchwork-Id: 1983454 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=nasilyan.com header.i=@nasilyan.com header.a=rsa-sha256 header.s=tey23rxsjton5kop5bydp3vc5ylkyjkg header.b=mPnmEfX+; dkim=pass (1024-bit key; unprotected) header.d=amazonses.com header.i=@amazonses.com header.a=rsa-sha256 header.s=uku4taia5b5tsbglxyj6zym32efj7xqv header.b=B3hNxZmI; 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 4X3BTw6tcwz1y1s for ; Wed, 11 Sep 2024 04:06:28 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CB7C2385841C for ; Tue, 10 Sep 2024 18:06:26 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from a6-15.smtp-out.eu-west-1.amazonses.com (a6-15.smtp-out.eu-west-1.amazonses.com [54.240.6.15]) by sourceware.org (Postfix) with ESMTPS id 692293858D39 for ; Tue, 10 Sep 2024 18:06:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 692293858D39 Authentication-Results: sourceware.org; dmarc=fail (p=quarantine dis=none) header.from=nasilyan.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=eu-west-1.amazonses.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 692293858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=54.240.6.15 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725991571; cv=none; b=ixu0WVSObjHszUxzmiRc1JTPKqXluhNEM2ho6tNE5NbIA2WRZD2cmySS//F+qNfutndC37XB0uDWcDLCY3l2E0LDWbVYI1Gqn78MDZQJjl/ykTG8KuRaSzm36mcROzyL31yJStbY3KaVb6t1tBdgIOU06amC+jTQwSh0atk8TbE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725991571; c=relaxed/simple; bh=9RkSBZR1EQ6grRdoh8q8EFFLKlXfyqCgcV2/Nac8SiU=; h=DKIM-Signature:DKIM-Signature:Subject:From:To:Date:Mime-Version: Message-ID; b=AbnQZo0oKVGBzcnPClDmc/ywYBRJJ2Fxq38vttxNkifn/zuanY1ntHYxzbpLdFJ8b62jiuQgncqRyXY6FZk6wfKcIsXq/i5+iKubz7sbg16aGrG+7vUSd4NtmkicXcXv30fm+fRegBjA+5TMn3R+4SiLftwPi5MOu59cV+n0+H8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=tey23rxsjton5kop5bydp3vc5ylkyjkg; d=nasilyan.com; t=1725991563; h=Subject:From:To:Date:Mime-Version:Content-Type:Content-Transfer-Encoding:References:Message-Id; bh=9RkSBZR1EQ6grRdoh8q8EFFLKlXfyqCgcV2/Nac8SiU=; b=mPnmEfX+9NxsS+JkKYbKOqqb4uET6jm7+Q/zioCHhDhdRqW/dN+qr7qbm7b/HwV/ W7k53X/NxtwgbuxSyQC3AU4+8YAwKq5JsE9+YeS1K/eZrONdXzThM/Fr0nDSBTmPlnr 89mQHFem2+zq4ptVcrTcbFEX5rLAdLOQnUI1URaI= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=uku4taia5b5tsbglxyj6zym32efj7xqv; d=amazonses.com; t=1725991563; h=Subject:From:To:Date:Mime-Version:Content-Type:Content-Transfer-Encoding:References:Message-Id:Feedback-ID; bh=9RkSBZR1EQ6grRdoh8q8EFFLKlXfyqCgcV2/Nac8SiU=; b=B3hNxZmIc8qBbw7DPZQaC1hmA0RAWWueko9R5RDa+FWoe8NorN0sZPT88vaPZzv/ RuSXnLMY2qCjOPUGmU/fqRqTotqExEJlXRSCs/1Z1d8icGzz3WikUv4rbispzkG5x5F 5S3hlDzmf521PJ4jK0ba48VkaGpRo8+GqSQIoHDU= Subject: [PATCH] c++: Don't crash when mangling member with anonymous union type [PR100632] From: =?utf-8?q?Simon_Martin?= To: =?utf-8?q?gcc-patches=40gcc=2Egnu=2Eorg?= Date: Tue, 10 Sep 2024 18:06:02 +0000 Mime-Version: 1.0 References: <20240910180559.50256-1-simon@nasilyan.com> X-Mailer: Amazon WorkMail Thread-Index: AQHbA6wYyt0Gs0eoQsaLkqF4bj0WIw== Thread-Topic: [PATCH] c++: Don't crash when mangling member with anonymous union type [PR100632] X-Original-Mailer: git-send-email 2.44.0 X-Wm-Sent-Timestamp: 1725991562 Message-ID: <01020191dd1d2e60-8ee35eb1-27fc-4408-82c6-19ab5f5d1f88-000000@eu-west-1.amazonses.com> Feedback-ID: ::1.eu-west-1.b24dn6frgCi6dh20skzbuMRr7UL8M6Soir/3ogtEjHQ=:AmazonSES X-SES-Outgoing: 2024.09.10-54.240.6.15 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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 We currently crash upon the following valid code (the case from the PR, invalid, can be made valid by simply adding a definition for f at line 2) === cut here === struct B { const int *p; }; template void f() {} struct Nested { union { int k; }; } nested; template void f(); === cut here === The problem is that because of the anonymous union, nested.k is represented as nested.$(decl_of_anon_union).k, and we run into an assert in write_member_name just before calling write_unqualified_name, because DECL_NAME ($decl_of_anon_union) is 0. This patch fixes this by relaxing the assert to also accept members with an ANON_AGGR_TYPE_P type, that are handled by write_unqualified_name just fine. Successfully tested on x86_64-pc-linux-gnu. PR c++/100632 gcc/cp/ChangeLog: * mangle.cc (write_member_name): Relax assert to accept anonymous unions. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/nontype-class67.C: New test. --- gcc/cp/mangle.cc | 3 ++- gcc/testsuite/g++.dg/cpp2a/nontype-class67.C | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/nontype-class67.C diff --git a/gcc/cp/mangle.cc b/gcc/cp/mangle.cc index 46dc6923add..11dc66c8d16 100644 --- a/gcc/cp/mangle.cc +++ b/gcc/cp/mangle.cc @@ -3255,7 +3255,8 @@ write_member_name (tree member) } else if (DECL_P (member)) { - gcc_assert (!DECL_OVERLOADED_OPERATOR_P (member)); + gcc_assert (ANON_AGGR_TYPE_P (TREE_TYPE (member)) + || !DECL_OVERLOADED_OPERATOR_P (member)); write_unqualified_name (member); } else if (TREE_CODE (member) == TEMPLATE_ID_EXPR) diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-class67.C b/gcc/testsuite/g++.dg/cpp2a/nontype-class67.C new file mode 100644 index 00000000000..accf4284883 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/nontype-class67.C @@ -0,0 +1,9 @@ +// PR c++/100632 +// { dg-do compile { target c++20 } } + +struct B { const int* p; }; +template void f() {} + +struct Nested { union { int k; }; } nested; + +template void f();