From 385df727848825df33f6acd796b4e34d1e07abd4 Mon Sep 17 00:00:00 2001 From: jsm28 Date: Fri, 25 Aug 2006 21:11:46 +0000 Subject: PR c/28299 * c-decl.c (start_function): Don't try to process prototype information from old declaration that isn't a function. testsuite: * 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. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@116435 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 6 ++++++ gcc/c-decl.c | 2 ++ gcc/testsuite/ChangeLog | 7 +++++++ gcc/testsuite/gcc.dg/funcdef-var-1.c | 10 ++++++++++ gcc/testsuite/gcc.dg/funcdef-var-2.c | 11 +++++++++++ gcc/testsuite/gcc.dg/pr20368-1.c | 2 +- gcc/testsuite/gcc.dg/pr20368-2.c | 2 +- gcc/testsuite/gcc.dg/pr20368-3.c | 2 +- 8 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/funcdef-var-1.c create mode 100644 gcc/testsuite/gcc.dg/funcdef-var-2.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 865d0156f9f..582ea4d8432 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2006-08-25 Joseph S. Myers + + PR c/28299 + * c-decl.c (start_function): Don't try to process prototype + information from old declaration that isn't a function. + 2006-08-25 Jan Hubicka PR target/28621 diff --git a/gcc/c-decl.c b/gcc/c-decl.c index 494c221f555..cf89191ae2e 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -5991,6 +5991,8 @@ start_function (struct c_declspecs *declspecs, struct c_declarator *declarator, /* 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 --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8b2850a34e0..85df20fdf7f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2006-08-25 Joseph S. Myers + + 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. + 2006-08-25 J"orn Rennecke gcc.dg/noncompile/pr16876.c: New test. diff --git a/gcc/testsuite/gcc.dg/funcdef-var-1.c b/gcc/testsuite/gcc.dg/funcdef-var-1.c new file mode 100644 index 00000000000..a685af7ac1c --- /dev/null +++ b/gcc/testsuite/gcc.dg/funcdef-var-1.c @@ -0,0 +1,10 @@ +/* Test ICE on defining function with a name previously declared as a + nonfunction. Bug 28299 from Bernhard Fischer + . */ +/* { 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 --git a/gcc/testsuite/gcc.dg/funcdef-var-2.c b/gcc/testsuite/gcc.dg/funcdef-var-2.c new file mode 100644 index 00000000000..744987ebf3b --- /dev/null +++ b/gcc/testsuite/gcc.dg/funcdef-var-2.c @@ -0,0 +1,11 @@ +/* Test ICE on defining function with a name previously declared as a + nonfunction. Bug 28299 from Bernhard Fischer . + Reduced testcase from Volker Reichelt . */ + +/* { 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 --git a/gcc/testsuite/gcc.dg/pr20368-1.c b/gcc/testsuite/gcc.dg/pr20368-1.c index a88c7f803b7..40ef9fe90be 100644 --- a/gcc/testsuite/gcc.dg/pr20368-1.c +++ b/gcc/testsuite/gcc.dg/pr20368-1.c @@ -7,6 +7,6 @@ extern __typeof (f) g; /* { dg-error "error: 'f' undeclared here \\(not in a fun int f (x) - float x; + float x; /* { dg-warning "warning: function declaration isn't a prototype" } */ { } diff --git a/gcc/testsuite/gcc.dg/pr20368-2.c b/gcc/testsuite/gcc.dg/pr20368-2.c index e3c8396233e..07bcbcec16d 100644 --- a/gcc/testsuite/gcc.dg/pr20368-2.c +++ b/gcc/testsuite/gcc.dg/pr20368-2.c @@ -7,6 +7,6 @@ extern __typeof (f) g; /* { dg-error "error: 'f' undeclared here \\(not in a fun int f (x) - float x; + float x; /* { dg-warning "warning: no previous prototype for 'f'" } */ { } diff --git a/gcc/testsuite/gcc.dg/pr20368-3.c b/gcc/testsuite/gcc.dg/pr20368-3.c index 32095999676..69c0bc81ce6 100644 --- a/gcc/testsuite/gcc.dg/pr20368-3.c +++ b/gcc/testsuite/gcc.dg/pr20368-3.c @@ -7,6 +7,6 @@ extern __typeof (f) g; /* { dg-error "error: 'f' undeclared here \\(not in a fun int f (x) - float x; + float x; /* { dg-warning "warning: no previous declaration for 'f'" } */ { } -- cgit v1.2.3