public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C PATCH] Fix ICE with __auto_type (PR c/65228)
@ 2015-02-27  9:44 Marek Polacek
  2015-02-27 13:11 ` Joseph Myers
  0 siblings, 1 reply; 2+ messages in thread
From: Marek Polacek @ 2015-02-27  9:44 UTC (permalink / raw)
  To: GCC Patches, Joseph Myers

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.

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" } */
+}

	Marek

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

* Re: [C PATCH] Fix ICE with __auto_type (PR c/65228)
  2015-02-27  9:44 [C PATCH] Fix ICE with __auto_type (PR c/65228) Marek Polacek
@ 2015-02-27 13:11 ` Joseph Myers
  0 siblings, 0 replies; 2+ messages in thread
From: Joseph Myers @ 2015-02-27 13:11 UTC (permalink / raw)
  To: Marek Polacek; +Cc: GCC Patches

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.

-- 
Joseph S. Myers
joseph@codesourcery.com

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

end of thread, other threads:[~2015-02-27 12:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-27  9:44 [C PATCH] Fix ICE with __auto_type (PR c/65228) Marek Polacek
2015-02-27 13:11 ` Joseph Myers

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