diff mbox

C PATCH for c/71573 (ICE with invalid redeclaration)

Message ID 20160728151808.GG7007@redhat.com
State New
Headers show

Commit Message

Marek Polacek July 28, 2016, 3:18 p.m. UTC
When we're trying to implicitly declare a function, we first search the scope
looking for whether the function identifier is already bound to a declaration.
But as the following test shows, we might find something else other than a
FUNCTION_DECL like we're expecting, which would mean that an ICE ensues.  So
return early not only for error_mark_nodes, but also for anything that isn't a
FUNCTION_DECL.

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

2016-07-28  Marek Polacek  <polacek@redhat.com>

	PR c/71573
	* c-decl.c (implicitly_declare): Return decl early not only for
	error_mark_nodes, but for anything that is not a FUNCTION_DECL.

	* gcc.dg/noncompile/pr71573.c: New test.


	Marek

Comments

Jeff Law July 29, 2016, 3:34 p.m. UTC | #1
On 07/28/2016 09:18 AM, Marek Polacek wrote:
> When we're trying to implicitly declare a function, we first search the scope
> looking for whether the function identifier is already bound to a declaration.
> But as the following test shows, we might find something else other than a
> FUNCTION_DECL like we're expecting, which would mean that an ICE ensues.  So
> return early not only for error_mark_nodes, but also for anything that isn't a
> FUNCTION_DECL.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
>
> 2016-07-28  Marek Polacek  <polacek@redhat.com>
>
> 	PR c/71573
> 	* c-decl.c (implicitly_declare): Return decl early not only for
> 	error_mark_nodes, but for anything that is not a FUNCTION_DECL.
>
> 	* gcc.dg/noncompile/pr71573.c: New test.
OK.
jeff
diff mbox

Patch

diff --git gcc/c/c-decl.c gcc/c/c-decl.c
index 41aabeb..24d3a45 100644
--- gcc/c/c-decl.c
+++ gcc/c/c-decl.c
@@ -3327,7 +3327,7 @@  implicitly_declare (location_t loc, tree functionid)
 
   if (decl)
     {
-      if (decl == error_mark_node)
+      if (TREE_CODE (decl) != FUNCTION_DECL)
 	return decl;
 
       /* FIXME: Objective-C has weird not-really-builtin functions
diff --git gcc/testsuite/gcc.dg/noncompile/pr71573.c gcc/testsuite/gcc.dg/noncompile/pr71573.c
index e69de29..8ace94a 100644
--- gcc/testsuite/gcc.dg/noncompile/pr71573.c
+++ gcc/testsuite/gcc.dg/noncompile/pr71573.c
@@ -0,0 +1,14 @@ 
+/* PR c/71573 */
+/* { dg-do compile } */
+
+void
+f1 (void)
+{
+  extern int t;
+}
+
+void
+f2 (void)
+{
+  t (0); /* { dg-error "called object .t. is not a function or function pointer" } */
+}