Message ID | 004b01d8321f$80e50fa0$82af2ee0$@nextmovesoftware.com |
---|---|
State | New |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> 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 49EF1385841F for <patchwork@sourceware.org>; Mon, 7 Mar 2022 12:33:52 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from server.nextmovesoftware.com (server.nextmovesoftware.com [162.254.253.69]) by sourceware.org (Postfix) with ESMTPS id 37309385842B for <gcc-patches@gcc.gnu.org>; Mon, 7 Mar 2022 12:33:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 37309385842B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nextmovesoftware.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nextmovesoftware.com; s=default; h=Content-Type:MIME-Version:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=FPxLy1Y98LyGjYF9WZ/CiHMNEgaEN3FLua5bvZNsScU=; b=FmGSiBZn3NP/rNkZvePl8hPL0t DeJT/N9w3UpRnCPKZvMBVMEQuuyZtGLXb4teh6zqImw+d9y5uh6TuZj1if5GBcRWI9P1wbSpcLQv+ RtYBLw9nPR1N3FmF8KfO6G+bxFQ/yA6Amsu0z0F+xWFeq1c78HnxrDKMaMjpaoqTHh7YG1U8JLpOJ ++XjfFySXvwTI4rYUiNcBtsFfvGGF503d/lB5BR7jBIicHfneX6tFNyDduKqMLm9sC1/j/jqMZg8w ls8yzyI4W88LvA1SBE1qIICsucF6Zga2R0+ZStWFrUQa02qYHFiI+Bl/g0j9Rxw5gRSRtjzjieU6M kAxOPLJw==; Received: from host86-186-213-42.range86-186.btcentralplus.com ([86.186.213.42]:54414 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from <roger@nextmovesoftware.com>) id 1nRCY2-00062p-KC for gcc-patches@gcc.gnu.org; Mon, 07 Mar 2022 07:33:10 -0500 From: "Roger Sayle" <roger@nextmovesoftware.com> To: <gcc-patches@gcc.gnu.org> Subject: [C++ PATCH] PR c++/96437: ICE-on-invalid-code error recovery. Date: Mon, 7 Mar 2022 12:33:07 -0000 Message-ID: <004b01d8321f$80e50fa0$82af2ee0$@nextmovesoftware.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_004C_01D8321F.80E50FA0" X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdgyHyXTW6gs1pcGTliINpj7JEJWgw== Content-Language: en-gb X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server.nextmovesoftware.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - nextmovesoftware.com X-Get-Message-Sender-Via: server.nextmovesoftware.com: authenticated_id: roger@nextmovesoftware.com X-Authenticated-Sender: server.nextmovesoftware.com: roger@nextmovesoftware.com X-Source: X-Source-Args: X-Source-Dir: X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
[C++] PR c++/96437: ICE-on-invalid-code error recovery.
|
|
Commit Message
Roger Sayle
March 7, 2022, 12:33 p.m. UTC
This patch fixes PR c++/96437 which is an ICE-on-invalid-code regression affecting mainline. This patch has been tested on x86_64-pc-linux-gnu, enabling languages c and c++, with make bootstrap and make -k check with no new failures. Ok for mainline? 2022-03-07 Roger Sayle <roger@nextmovesoftware.com> gcc/cp/ChangeLog PR c++/96437 * parser.cc (synthesize_implicit_template_parm): Check that TREE_VALUE (new_parm) isn't error_mark_node before setting its DECL_VIRTUAL_P. gcc/testsuite/ChangeLog PR c++/96437 * g++.dg/pr96437.C: New test case. Thanks in advance, Roger --
Comments
On 3/7/22 08:33, Roger Sayle wrote: > > This patch fixes PR c++/96437 which is an ICE-on-invalid-code regression > affecting mainline. > > This patch has been tested on x86_64-pc-linux-gnu, enabling languages > c and c++, with make bootstrap and make -k check with no new failures. > Ok for mainline? > > 2022-03-07 Roger Sayle <roger@nextmovesoftware.com> > > gcc/cp/ChangeLog > PR c++/96437 > * parser.cc (synthesize_implicit_template_parm): Check that > TREE_VALUE (new_parm) isn't error_mark_node before setting its > DECL_VIRTUAL_P. > > gcc/testsuite/ChangeLog > PR c++/96437 > * g++.dg/pr96437.C: New test case. > + if (TREE_VALUE (new_parm) != error_mark_node) > + DECL_VIRTUAL_P (TREE_VALUE (new_parm)) = true; Hmm, I wonder about returning early if there was an error, but this is fine as is. > +/* { dg-options "-O2" } */ This also seems unneeded for this test. Also, please put tests in a subdirectory of g++.dg, not the top directory. This one might go in cpp2a/ since it's a C++20 feature. OK with those adjustments. Jason
Hi Jason, Very many thanks for your reviews/approvals of these ICE-on-invalid-code fixes. > > + if (TREE_VALUE (new_parm) != error_mark_node) > > + DECL_VIRTUAL_P (TREE_VALUE (new_parm)) = true; > > Hmm, I wonder about returning early if there was an error, but this is fine as is. The challenge here is the need to perform "current_binding_level = entry_scope;" required to restore the parser state before returning. Now that the parser is written in C++, we could (in theory) make more use of destructors to automatically restore/pop state, making it safe(r) to just "return error_mark_node" immediately in more places. > > +/* { dg-options "-O2" } */ > > This also seems unneeded for this test. Doh! Force of habit (from working in the middle-end). Consider this removed from all the test cases below. Is there any chance I could ask you to also look at these (that probably slipped through the net), though PR 84964 might require a nod from a middle-end maintainer. PR c++/39751: https://gcc.gnu.org/pipermail/gcc-patches/2022-February/590951.html PR c++/84964: https://gcc.gnu.org/pipermail/gcc-patches/2022-February/590961.html PR c++/95999: https://gcc.gnu.org/pipermail/gcc-patches/2022-February/590653.html PR c++/96442: https://gcc.gnu.org/pipermail/gcc-patches/2022-February/590716.html Very many thanks again for your help/reviews. Much appreciated. Roger --
On 3/9/22 14:35, Roger Sayle wrote: > > Hi Jason, > > Very many thanks for your reviews/approvals of these ICE-on-invalid-code fixes. > >>> + if (TREE_VALUE (new_parm) != error_mark_node) >>> + DECL_VIRTUAL_P (TREE_VALUE (new_parm)) = true; >> >> Hmm, I wonder about returning early if there was an error, but this is fine as is. > > The challenge here is the need to perform "current_binding_level = entry_scope;" > required to restore the parser state before returning. Now that the parser is > written in C++, we could (in theory) make more use of destructors to automatically > restore/pop state, making it safe(r) to just "return error_mark_node" immediately > in more places. Yes, e.g. auto ov = make_temp_override (current_binding_level); >>> +/* { dg-options "-O2" } */ >> >> This also seems unneeded for this test. > > Doh! Force of habit (from working in the middle-end). Consider this removed > from all the test cases below. > > Is there any chance I could ask you to also look at these (that probably slipped > through the net), though PR 84964 might require a nod from a middle-end maintainer. > > PR c++/39751: https://gcc.gnu.org/pipermail/gcc-patches/2022-February/590951.html > PR c++/84964: https://gcc.gnu.org/pipermail/gcc-patches/2022-February/590961.html > PR c++/95999: https://gcc.gnu.org/pipermail/gcc-patches/2022-February/590653.html > PR c++/96442: https://gcc.gnu.org/pipermail/gcc-patches/2022-February/590716.html Will do. Jason
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 03d99ab..992f839 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -48217,7 +48217,8 @@ synthesize_implicit_template_parm (cp_parser *parser, tree constr) function template is equivalent to an explicit template. Note that DECL_ARTIFICIAL is used elsewhere for template parameters. */ - DECL_VIRTUAL_P (TREE_VALUE (new_parm)) = true; + if (TREE_VALUE (new_parm) != error_mark_node) + DECL_VIRTUAL_P (TREE_VALUE (new_parm)) = true; // Chain the new parameter to the list of implicit parameters. if (parser->implicit_template_parms) diff --git a/gcc/testsuite/g++.dg/pr96437.C b/gcc/testsuite/g++.dg/pr96437.C new file mode 100644 index 0000000..00c4141 --- /dev/null +++ b/gcc/testsuite/g++.dg/pr96437.C @@ -0,0 +1,5 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-excess-errors "" } */ + +template <()> void A(auto){}