diff mbox

[C] Fix ICE with __auto_type (PR c/65228)

Message ID 20150227091418.GJ22272@redhat.com
State New
Headers show

Commit Message

Marek Polacek Feb. 27, 2015, 9:14 a.m. UTC
This PR points out that we can ICE in case we have __auto_type with undeclared
variable: grokdeclarator returns error_mark_node, so check for that before
accessing decl's TREE_CODE (can't use error_operand_p here as that would cause
bogus diagnostics be emitted).

Bootstrapped/regtested on x86_64-linux, ok for trunk and 4.9?

2015-02-26  Marek Polacek  <polacek@redhat.com>

	PR c/65228
	* c-decl.c (start_decl): Return NULL_TREE if decl is an error node.

	* gcc.dg/pr65228.c: New test.


	Marek

Comments

Joseph Myers Feb. 27, 2015, 12:05 p.m. UTC | #1
On Fri, 27 Feb 2015, Marek Polacek wrote:

> This PR points out that we can ICE in case we have __auto_type with undeclared
> variable: grokdeclarator returns error_mark_node, so check for that before
> accessing decl's TREE_CODE (can't use error_operand_p here as that would cause
> bogus diagnostics be emitted).
> 
> Bootstrapped/regtested on x86_64-linux, ok for trunk and 4.9?
> 
> 2015-02-26  Marek Polacek  <polacek@redhat.com>
> 
> 	PR c/65228
> 	* c-decl.c (start_decl): Return NULL_TREE if decl is an error node.
> 
> 	* gcc.dg/pr65228.c: New test.

OK.
diff mbox

Patch

diff --git gcc/c/c-decl.c gcc/c/c-decl.c
index 8eeee9c..3bf1fc6 100644
--- gcc/c/c-decl.c
+++ gcc/c/c-decl.c
@@ -4460,8 +4460,8 @@  start_decl (struct c_declarator *declarator, struct c_declspecs *declspecs,
   decl = grokdeclarator (declarator, declspecs,
 			 NORMAL, initialized, NULL, &attributes, &expr, NULL,
 			 deprecated_state);
-  if (!decl)
-    return 0;
+  if (!decl || decl == error_mark_node)
+    return NULL_TREE;
 
   if (expr)
     add_stmt (fold_convert (void_type_node, expr));
diff --git gcc/testsuite/gcc.dg/pr65228.c gcc/testsuite/gcc.dg/pr65228.c
index e69de29..fd83238 100644
--- gcc/testsuite/gcc.dg/pr65228.c
+++ gcc/testsuite/gcc.dg/pr65228.c
@@ -0,0 +1,11 @@ 
+/* PR c/65228 */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+__auto_type a = b; /* { dg-error "undeclared" } */
+
+void
+f (void)
+{
+  __auto_type c = d; /* { dg-error "undeclared" } */
+}