public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ PATCH] PR c++/96437: ICE-on-invalid-code error recovery.
@ 2022-03-07 12:33 Roger Sayle
  2022-03-07 23:43 ` Jason Merrill
  0 siblings, 1 reply; 4+ messages in thread
From: Roger Sayle @ 2022-03-07 12:33 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 588 bytes --]


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
--


[-- Attachment #2: patchcp6.txt --]
[-- Type: text/plain, Size: 949 bytes --]

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){}

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [C++ PATCH] PR c++/96437: ICE-on-invalid-code error recovery.
  2022-03-07 12:33 [C++ PATCH] PR c++/96437: ICE-on-invalid-code error recovery Roger Sayle
@ 2022-03-07 23:43 ` Jason Merrill
  2022-03-09 18:35   ` Roger Sayle
  0 siblings, 1 reply; 4+ messages in thread
From: Jason Merrill @ 2022-03-07 23:43 UTC (permalink / raw)
  To: Roger Sayle, gcc-patches

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [C++ PATCH] PR c++/96437: ICE-on-invalid-code error recovery.
  2022-03-07 23:43 ` Jason Merrill
@ 2022-03-09 18:35   ` Roger Sayle
  2022-03-10  4:18     ` Jason Merrill
  0 siblings, 1 reply; 4+ messages in thread
From: Roger Sayle @ 2022-03-09 18:35 UTC (permalink / raw)
  To: 'Jason Merrill'; +Cc: gcc-patches


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
--



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [C++ PATCH] PR c++/96437: ICE-on-invalid-code error recovery.
  2022-03-09 18:35   ` Roger Sayle
@ 2022-03-10  4:18     ` Jason Merrill
  0 siblings, 0 replies; 4+ messages in thread
From: Jason Merrill @ 2022-03-10  4:18 UTC (permalink / raw)
  To: Roger Sayle; +Cc: gcc-patches

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-03-10  4:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-07 12:33 [C++ PATCH] PR c++/96437: ICE-on-invalid-code error recovery Roger Sayle
2022-03-07 23:43 ` Jason Merrill
2022-03-09 18:35   ` Roger Sayle
2022-03-10  4:18     ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).