From patchwork Thu Sep 12 11:23:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Simon Martin X-Patchwork-Id: 1984623 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=cJJrRtXS; dkim=pass (1024-bit key; unprotected) header.d=amazonses.com header.i=@amazonses.com header.a=rsa-sha256 header.s=uku4taia5b5tsbglxyj6zym32efj7xqv header.b=MK07mgpz; 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 4X4FSZ230sz1y1y for ; Thu, 12 Sep 2024 21:23:54 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B2ADE385842A for ; Thu, 12 Sep 2024 11:23:52 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from a2-73.smtp-out.eu-west-1.amazonses.com (a2-73.smtp-out.eu-west-1.amazonses.com [54.240.2.73]) by sourceware.org (Postfix) with ESMTPS id 5012C3858D28 for ; Thu, 12 Sep 2024 11:23:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5012C3858D28 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 5012C3858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=54.240.2.73 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726140214; cv=none; b=bX3kktuyJtdUeegaiicq7fSB4tWl+nY1s9zzKTH5D0cmnU9Tu6iWWx1BRoc4va89+qSEYtBDDMhCFJM4dwB8LnzMBZb9+dRGwX/+jHVs+/S3JXqfrWKz4SgkZsMCbY3eNFefL5ukZHVB8C8TUlTX76+j5/CbT8vsTDkHmJPtpL4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726140214; c=relaxed/simple; bh=lMUoyvsMV/P/Qk2Wsm2xYAWRLWY1GtFVnk87TbH9+F0=; h=DKIM-Signature:DKIM-Signature:Subject:From:To:Date:Mime-Version: Message-ID; b=WGGLcpUWCl7YN4gTe3lETk5/CjPJAnDINtRaUg5Gsg97MIlTJxa/Rfhtz1lO/oFsaJc5/D51iwyZ8eSETQARpi8hIY5oadK5ZfGbGuYyshIcEjo+7z57WfOBkeu08zoPrqXk/HNkgCK3atnvpL8rhUaWrMNklR2Qp101RCOhCTs= 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=1726140211; h=Subject:From:To:Date:Mime-Version:Content-Type:In-Reply-To:References:Message-Id; bh=lMUoyvsMV/P/Qk2Wsm2xYAWRLWY1GtFVnk87TbH9+F0=; b=cJJrRtXSjJl/7l1kc9xuAdomqhr1KU2n91LDesGs8yNC9EpdDrsyWHIZ3Gv7hcdd vsv7pPtKP0ifMykeZGpLhESVYg5d07k8HehW1FGm0nHfMEPmikSvnAKIYmNkNTr0i7n wpIRmpI0ZgHot1o9B44I/3zFdJOD0GC20u6yCG0I= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=uku4taia5b5tsbglxyj6zym32efj7xqv; d=amazonses.com; t=1726140211; h=Subject:From:To:Date:Mime-Version:Content-Type:In-Reply-To:References:Message-Id:Feedback-ID; bh=lMUoyvsMV/P/Qk2Wsm2xYAWRLWY1GtFVnk87TbH9+F0=; b=MK07mgpzGAfs5rhPZqHY+zBMdLd9FAS7URkjFd74UlI8Cs8f2EeYdNJVkKEwAvJw 6H1DU7Y+cTXdEQoeLZjr8nlbkDVcs2PdcOmNOe4qAERJHJUFqdw9H+UcGjOf7q08np6 VMHUskqfWIBsmBlzZM12t7n/UR7ch0qBwWlXmfQQ= Subject: [PATCH v2] c++: Don't crash when mangling member with anonymous union or template types [PR100632, PR109790] From: =?utf-8?q?Simon_Martin?= To: =?utf-8?q?gcc-patches=40gcc=2Egnu=2Eorg?= Date: Thu, 12 Sep 2024 11:23:30 +0000 Mime-Version: 1.0 In-Reply-To: <01020191dd1d2e60-8ee35eb1-27fc-4408-82c6-19ab5f5d1f88-000000@eu-west-1.amazonses.com> References: <20240910180559.50256-1-simon@nasilyan.com> <01020191dd1d2e60-8ee35eb1-27fc-4408-82c6-19ab5f5d1f88-000000@eu-west-1.amazonses.com> <8345CB5C-D73E-4376-B0BE-605281D2EDE6@nasilyan.com> X-Mailer: Amazon WorkMail Thread-Index: AQHbA6wYyt0Gs0eoQsaLkqF4bj0WIwBWhmFW Thread-Topic: [PATCH v2] c++: Don't crash when mangling member with anonymous union or template types [PR100632, PR109790] X-Original-Mailer: MailMate (1.13.2r5673) X-Wm-Sent-Timestamp: 1726140210 Message-ID: <01020191e5f95f25-ce2839c1-94cf-4be4-9963-612271b0a468-000000@eu-west-1.amazonses.com> Feedback-ID: ::1.eu-west-1.b24dn6frgCi6dh20skzbuMRr7UL8M6Soir/3ogtEjHQ=:AmazonSES X-SES-Outgoing: 2024.09.12-54.240.2.73 X-Spam-Status: No, score=-13.4 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 Hi, While looking at more open PRs, I have discovered that the problem reported in PR109790 is very similar to that in PR100632, so I’m combining both in a single patch attached here. The fix is similar to the one I initially submitted, only more general and I believe better. Successfully tested on x86_64-pc-linux-gnu. OK for trunk? Thanks, Simon On 10 Sep 2024, at 20:06, Simon Martin wrote: > 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(); > -- > 2.44.0 From 3ce65d06310e694bd6a3918d87049523951c0762 Mon Sep 17 00:00:00 2001 From: Simon Martin Date: Mon, 9 Sep 2024 09:31:10 +0200 Subject: [PATCH] c++: Don't crash when mangling member with anonymous union or template type [PR100632, PR109790] We currently crash upon mangling members that have an anonymous union or a template type. The problem is that before calling write_unqualified_name, write_member_name has an assert that assumes that it has an IDENTIFIER_NODE in its hand. However it's incorrect: it has an anonymous union in PR100632, and a template in PR109790. This patch fixes this by relaxing the assert to accept members that are not identifiers, that are handled by write_unqualified_name just fine. Successfully tested on x86_64-pc-linux-gnu. PR c++/109790 PR c++/100632 gcc/cp/ChangeLog: * mangle.cc (write_member_name): Relax assert to accept members that are not identifiers. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/decltype83.C: New test. * g++.dg/cpp1y/lambda-ice3.C: New test. * g++.dg/cpp2a/nontype-class67.C: New test. --- gcc/cp/mangle.cc | 3 ++- gcc/testsuite/g++.dg/cpp0x/decltype83.C | 13 +++++++++++++ gcc/testsuite/g++.dg/cpp1y/lambda-ice3.C | 12 ++++++++++++ gcc/testsuite/g++.dg/cpp2a/nontype-class67.C | 9 +++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/decltype83.C create mode 100644 gcc/testsuite/g++.dg/cpp1y/lambda-ice3.C 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..a63ae9f7ac6 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 (!identifier_p (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/cpp0x/decltype83.C b/gcc/testsuite/g++.dg/cpp0x/decltype83.C new file mode 100644 index 00000000000..db104f333aa --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/decltype83.C @@ -0,0 +1,13 @@ +// PR c++/109790 +// { dg-do compile { target c++11 } } + +struct A { + template void operator+(T); +}; + +template +decltype(&A::operator+) f(); + +int main() { + f(); +} diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-ice3.C b/gcc/testsuite/g++.dg/cpp1y/lambda-ice3.C new file mode 100644 index 00000000000..49261aaabb7 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/lambda-ice3.C @@ -0,0 +1,12 @@ +// PR c++/109790 +// { dg-do compile { target c++14 } } + +auto ll = [](auto ... ){}; +template + void mm(void (_Impl::*__p)(_Args) const); +template +using __impl_for = decltype(mm(&decltype(ll)::operator()<_Ts>)); +template __impl_for<_Ts> f() { } +void aaa() { + f(); +} 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();