This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch for bug 28299


This patch fixes bug 28299, an ICE when defining a function with an
old declaration in the current scope that isn't a function
declaration.  By ignoring that old declaration in start_function, we
then get the desired error from pushdecl instead of an ICE.

Bootstrapped with no regressions on i686-pc-linux-gnu.  Applied to
mainline.  Will apply to 4.1 branch and 4.0 branch subject to testing
there.

2006-08-25  Joseph S. Myers  <joseph@codesourcery.com>

	PR c/28299
	* c-decl.c (start_function): Don't try to process prototype
	information from old declaration that isn't a function.

testsuite:
2006-08-25  Joseph S. Myers  <joseph@codesourcery.com>

	PR c/28299
	* gcc.dg/funcdef-var-1.c, gcc.dg/funcdef-var-2.c: New tests.
	* gcc.dg/pr20368-1.c, gcc.dg/pr20368-2.c, gcc.dg/pr20368-3.c:
	Expect extra diagnostics.

diff -rupN GCC.orig/gcc/c-decl.c GCC/gcc/c-decl.c
--- GCC.orig/gcc/c-decl.c	2006-08-16 11:27:15.000000000 +0000
+++ GCC/gcc/c-decl.c	2006-08-25 16:07:38.000000000 +0000
@@ -5991,6 +5991,8 @@ start_function (struct c_declspecs *decl
   /* If this definition isn't a prototype and we had a prototype declaration
      before, copy the arg type info from that prototype.  */
   old_decl = lookup_name_in_scope (DECL_NAME (decl1), current_scope);
+  if (old_decl && TREE_CODE (old_decl) != FUNCTION_DECL)
+    old_decl = 0;
   current_function_prototype_locus = UNKNOWN_LOCATION;
   current_function_prototype_built_in = false;
   current_function_prototype_arg_types = NULL_TREE;
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/funcdef-var-1.c GCC/gcc/testsuite/gcc.dg/funcdef-var-1.c
--- GCC.orig/gcc/testsuite/gcc.dg/funcdef-var-1.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/funcdef-var-1.c	2006-08-25 18:46:50.000000000 +0000
@@ -0,0 +1,10 @@
+/* Test ICE on defining function with a name previously declared as a
+   nonfunction.  Bug 28299 from Bernhard Fischer
+   <aldot@gcc.gnu.org>.  */
+/* { dg-do compile } */
+/* { dg-options "-Wmissing-prototypes" } */
+
+extern __typeof(foo) foo __asm__(""); /* { dg-error "undeclared" } */
+/* { dg-error "previous declaration" "previous declaration" { target *-*-* } 7 } */
+void *foo (void) {} /* { dg-error "redeclared as different kind of symbol" } */
+/* { dg-warning "no previous prototype" "no previous prototype" { target *-*-* } 9 } */
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/funcdef-var-2.c GCC/gcc/testsuite/gcc.dg/funcdef-var-2.c
--- GCC.orig/gcc/testsuite/gcc.dg/funcdef-var-2.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/funcdef-var-2.c	2006-08-25 18:47:25.000000000 +0000
@@ -0,0 +1,11 @@
+/* Test ICE on defining function with a name previously declared as a
+   nonfunction.  Bug 28299 from Bernhard Fischer <aldot@gcc.gnu.org>.
+   Reduced testcase from Volker Reichelt <reichelt@gcc.gnu.org>.  */
+
+/* { dg-do compile } */
+/* { dg-options "-Wmissing-prototypes" } */
+
+int foo;
+/* { dg-error "previous declaration" "previous declaration" { target *-*-* } 8 } */
+void foo () {} /* { dg-error "redeclared as different kind of symbol" } */
+/* { dg-warning "no previous prototype" "no previous prototype" { target *-*-* } 10 } */
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/pr20368-1.c GCC/gcc/testsuite/gcc.dg/pr20368-1.c
--- GCC.orig/gcc/testsuite/gcc.dg/pr20368-1.c	2005-10-28 23:28:52.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/pr20368-1.c	2006-08-25 20:58:52.000000000 +0000
@@ -7,6 +7,6 @@ extern __typeof (f) g; /* { dg-error "er
 
 int
 f (x)
-     float x;
+     float x; /* { dg-warning "warning: function declaration isn't a prototype" } */
 {
 }
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/pr20368-2.c GCC/gcc/testsuite/gcc.dg/pr20368-2.c
--- GCC.orig/gcc/testsuite/gcc.dg/pr20368-2.c	2005-10-28 23:28:52.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/pr20368-2.c	2006-08-25 20:59:12.000000000 +0000
@@ -7,6 +7,6 @@ extern __typeof (f) g; /* { dg-error "er
 
 int
 f (x)
-     float x;
+     float x; /* { dg-warning "warning: no previous prototype for 'f'" } */
 {
 }
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/pr20368-3.c GCC/gcc/testsuite/gcc.dg/pr20368-3.c
--- GCC.orig/gcc/testsuite/gcc.dg/pr20368-3.c	2005-10-28 23:28:52.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/pr20368-3.c	2006-08-25 20:59:37.000000000 +0000
@@ -7,6 +7,6 @@ extern __typeof (f) g; /* { dg-error "er
 
 int
 f (x)
-     float x;
+     float x; /* { dg-warning "warning: no previous declaration for 'f'" } */
 {
 }

-- 
Joseph S. Myers
joseph@codesourcery.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]