From patchwork Wed Jun 5 08:13:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Martin X-Patchwork-Id: 1943701 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=xce2voaxvxhmx73p47whqmbxwwvd7qkl header.b=AK2wmr7t; dkim=pass (1024-bit key; unprotected) header.d=amazonses.com header.i=@amazonses.com header.a=rsa-sha256 header.s=uku4taia5b5tsbglxyj6zym32efj7xqv header.b=RDKElVhq; 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 4VvKwv742xz20KL for ; Wed, 5 Jun 2024 18:13:51 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 370C5383938E for ; Wed, 5 Jun 2024 08:13:49 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from a2-27.smtp-out.eu-west-1.amazonses.com (a2-27.smtp-out.eu-west-1.amazonses.com [54.240.2.27]) by sourceware.org (Postfix) with ESMTPS id C04B2386182C for ; Wed, 5 Jun 2024 08:13:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C04B2386182C 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 C04B2386182C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=54.240.2.27 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717575197; cv=none; b=ZkS7We7JHxB+bl/EeI2inufPfw6G545xn6WyVOjvyilnjQL2lVmRttujNDMQrT7GycMpfh1oMstYvkapA9908axnj+rehkXY7TuxS0NTruJjYGXeDKKr+XS2Il/HBkqAR9N3UalPXkMmaqrFrtfYuBi7FApQRsdnzXxNYRrF21Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717575197; c=relaxed/simple; bh=/JHL8KcnZz0ynCXpN/slrtpswlGi820XxqPMgG7Q/JA=; h=DKIM-Signature:DKIM-Signature:Subject:From:To:Date:Mime-Version: Message-ID; b=rBYoqA1GhdwOjPwcONseDAzaDblgcjhArrvfrrfvYcRyakXZszXWZnRnQngW7+JyvEDq0hMTjNdprmHXhqKMR2986hOs2+WaApPDoAqNtn85BvuGOeg0eHmuNMUnApez+48soef63Q8D5Dw6xLe8rFu5OsY0RH4OfrwIXbh99AU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=xce2voaxvxhmx73p47whqmbxwwvd7qkl; d=nasilyan.com; t=1717575194; h=Subject:From:To:Date:Mime-Version:Content-Type:Content-Transfer-Encoding:References:Message-Id; bh=/JHL8KcnZz0ynCXpN/slrtpswlGi820XxqPMgG7Q/JA=; b=AK2wmr7tANYqwuULKBUH88/bMjjO2za4ISA5KEZ5unEmT6b/+vjV3U7dlT0mDEdH Ak58kD05Z3MEsqp1kWc9EDKOuVsfx7jD51roLhR/A2Fi1h5j8c3OuIa3jIT3wr37mOK hn6op7ZA+y6MeBN2K0V30shEmZP+m72dRFIWb5Vg= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=uku4taia5b5tsbglxyj6zym32efj7xqv; d=amazonses.com; t=1717575194; h=Subject:From:To:Date:Mime-Version:Content-Type:Content-Transfer-Encoding:References:Message-Id:Feedback-ID; bh=/JHL8KcnZz0ynCXpN/slrtpswlGi820XxqPMgG7Q/JA=; b=RDKElVhqQo3DZJBXQg/PpKHtdqIu+rujw/2d6xiHc/tqgPB7vHFrfXL1Lx8e301H SeZGo7jsFA/6K7Wwa0jRGfwBBA0CZM33mrEGp82I/resGhZIZsEZirg9z/Nw/bVoA8s /7jm0Jiw7+7YMBzjjPaocN/55IhatWrRC17EQl/o= Subject: [PATCH] c++: Handle erroneous DECL_LOCAL_DECL_ALIAS in duplicate_decls [PR107575] From: =?utf-8?q?Simon_Martin?= To: =?utf-8?q?gcc-patches=40gcc=2Egnu=2Eorg?= Date: Wed, 5 Jun 2024 08:13:14 +0000 Mime-Version: 1.0 References: <20240605081311.97544-1-simon@nasilyan.com> X-Mailer: Amazon WorkMail Thread-Index: AQHatyA1aN4LzfXwQlWqUEzN+QssNg== Thread-Topic: [PATCH] c++: Handle erroneous DECL_LOCAL_DECL_ALIAS in duplicate_decls [PR107575] X-Original-Mailer: git-send-email 2.44.0 X-Wm-Sent-Timestamp: 1717575193 Message-ID: <0102018fe7759751-88e2bb17-ead4-4cf0-a199-fa6231f73b49-000000@eu-west-1.amazonses.com> Feedback-ID: ::1.eu-west-1.b24dn6frgCi6dh20skzbuMRr7UL8M6Soir/3ogtEjHQ=:AmazonSES X-SES-Outgoing: 2024.06.05-54.240.2.27 X-Spam-Status: No, score=-12.8 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, T_SCC_BODY_TEXT_LINE 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 ICE upon the following because we don't properly handle local functions with an error_mark_node as DECL_LOCAL_DECL_ALIAS in duplicate_decls. === cut here === void f (void) { virtual int f (void) const; virtual int f (void); } === cut here === This patch fixes this by checking for error_mark_node. Successfully tested on x86_64-pc-linux-gnu. PR c++/107575 gcc/cp/ChangeLog: * decl.cc (duplicate_decls): Check for error_mark_node DECL_LOCAL_DECL_ALIAS. gcc/testsuite/ChangeLog: * g++.dg/parse/crash74.C: New test. --- gcc/cp/decl.cc | 11 +++++++---- gcc/testsuite/g++.dg/parse/crash74.C | 11 +++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/parse/crash74.C diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index d481e1ec074..2ae46143d70 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -2792,10 +2792,13 @@ duplicate_decls (tree newdecl, tree olddecl, bool hiding, bool was_hidden) retrofit_lang_decl (newdecl); tree alias = DECL_LOCAL_DECL_ALIAS (newdecl) = DECL_LOCAL_DECL_ALIAS (olddecl); - DECL_ATTRIBUTES (alias) - = (*targetm.merge_decl_attributes) (alias, newdecl); - if (TREE_CODE (newdecl) == FUNCTION_DECL) - merge_attribute_bits (newdecl, alias); + if (alias != error_mark_node) + { + DECL_ATTRIBUTES (alias) = + (*targetm.merge_decl_attributes) (alias, newdecl); + if (TREE_CODE (newdecl) == FUNCTION_DECL) + merge_attribute_bits (newdecl, alias); + } } } diff --git a/gcc/testsuite/g++.dg/parse/crash74.C b/gcc/testsuite/g++.dg/parse/crash74.C new file mode 100644 index 00000000000..a7ba5094be6 --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/crash74.C @@ -0,0 +1,11 @@ +// PR c++/107575 + +void f (void) { + virtual int f (void) const; // { dg-line line_4 } + virtual int f (void); // { dg-line line_5 } +} + +// { dg-error "outside class declaration" {} { target *-*-* } line_4 } +// { dg-error "cannot have cv-qualifier" {} { target *-*-* } line_4 } +// { dg-error "ambiguating new declaration of" {} { target *-*-* } line_4 } +// { dg-error "outside class declaration" {} { target *-*-* } line_5 }