[C++] PR c++/96440: ICE-on-invalid-code error recovery.

Message ID 005e01d83222$9b812a80$d2837f80$@nextmovesoftware.com
State New
Headers
Series [C++] PR c++/96440: ICE-on-invalid-code error recovery. |

Commit Message

Roger Sayle March 7, 2022, 12:55 p.m. UTC
  This patch fixes PR c++/96440 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++/96440
	* decl.cc (start_decl): Defend against prefix_attributes being
	error_mark_node.

gcc/testsuite/ChangeLog
	PR c++/96440
	* g++.dg/pr96440.C: New test case.

Roger
--
  

Comments

Jason Merrill March 7, 2022, 11:45 p.m. UTC | #1
On 3/7/22 08:55, Roger Sayle wrote:
> 
> This patch fixes PR c++/96440 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++/96440
> 	* decl.cc (start_decl): Defend against prefix_attributes being
> 	error_mark_node.
> 
> gcc/testsuite/ChangeLog
> 	PR c++/96440
> 	* g++.dg/pr96440.C: New test case.

> +/* { dg-options "-O2" } */

Please remove this line and put the test in g++.dg/cpp0x/

OK with those changes.

Jason
  

Patch

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 7f80f9d..de41b4d 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -5483,13 +5483,15 @@  start_decl (const cp_declarator *declarator,
 
   *pushed_scope_p = NULL_TREE;
 
-  attributes = chainon (attributes, prefix_attributes);
+  if (prefix_attributes != error_mark_node)
+    attributes = chainon (attributes, prefix_attributes);
 
   decl = grokdeclarator (declarator, declspecs, NORMAL, initialized,
 			 &attributes);
 
   if (decl == NULL_TREE || VOID_TYPE_P (decl)
-      || decl == error_mark_node)
+      || decl == error_mark_node
+      || prefix_attributes == error_mark_node)
     return error_mark_node;
 
   context = CP_DECL_CONTEXT (decl);
diff --git a/gcc/testsuite/g++.dg/pr96440.C b/gcc/testsuite/g++.dg/pr96440.C
new file mode 100644
index 0000000..212271f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr96440.C
@@ -0,0 +1,5 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+/* { dg-excess-errors "" } */
+
+auto alignas a [[]] [[const]] ();