diff options
author | phython <phython@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-12-21 17:01:08 +0000 |
---|---|---|
committer | phython <phython@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-12-21 17:01:08 +0000 |
commit | 61ba37bfdc89277570f40931fdfeb82dfefc5585 (patch) | |
tree | 4f41c122c72dec3b860a1cabdb23536dbf18fbee /gcc | |
parent | fedcccb5f9b79c9776b1429e3b4338e28efdef1f (diff) | |
download | gcc-61ba37bfdc89277570f40931fdfeb82dfefc5585.tar.gz |
2004-12-19 James A. Morrison <phython@gcc.gnu.org>
PR c/18596
* c-parse.in (initdcl): Don't process a declaration if start_decl fails.
(notype_initdcl): Don't process a declaration if start_decl fails.
* c-decl.c (start_decl): Fail if grokdeclarator fails.
(grokdeclarator): Fail if a function definition has an invalid storage
class.
* c-typeck.c (start_init): Treat error_mark_node the same as 0.
testsuite:
PR c/18596
* gcc.dg/funcdef-storage-1.c (foo): Remove.
* gcc.dg/pr18596-1.c: Use dg-error.
(dg-options): Use -fno-unit-at-a-time.
* gcc.dg/pr18596-2.c: New test.
* gcc.dg/pr18596-3.c: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@92459 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 10 | ||||
-rw-r--r-- | gcc/c-decl.c | 18 | ||||
-rw-r--r-- | gcc/c-parse.in | 26 | ||||
-rw-r--r-- | gcc/c-typeck.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 9 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/funcdef-storage-1.c | 6 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr18596-1.c | 36 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr18596-2.c | 39 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr18596-3.c | 14 |
9 files changed, 137 insertions, 23 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f65773c70c0..3fc04174332 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2004-12-21 James A. Morrison <phython@gcc.gnu.org> + + PR c/18596 + * c-parse.in (initdcl): Don't process a declaration if start_decl fails. + (notype_initdcl): Don't process a declaration if start_decl fails. + * c-decl.c (start_decl): Fail if grokdeclarator fails. + (grokdeclarator): Fail if a function definition has an invalid storage + class. + * c-typeck.c (start_init): Treat error_mark_node the same as 0. + 2004-12-21 Richard Henderson <rth@redhat.com> * config/i386/i386.c (x86_sse_split_regs): Rename from diff --git a/gcc/c-decl.c b/gcc/c-decl.c index 97420d16cc2..f881ea8e052 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -2964,6 +2964,8 @@ start_decl (struct c_declarator *declarator, struct c_declspecs *declspecs, decl = grokdeclarator (declarator, declspecs, NORMAL, initialized, NULL); + if (!decl) + return 0; deprecated_state = DEPRECATED_NORMAL; @@ -4437,14 +4439,9 @@ grokdeclarator (const struct c_declarator *declarator, } else if (TREE_CODE (type) == FUNCTION_TYPE) { - decl = build_decl (FUNCTION_DECL, declarator->u.id, type); - decl = build_decl_attribute_variant (decl, decl_attr); - if (storage_class == csc_register || threadp) { error ("invalid storage class for function %qs", name); - if (DECL_INITIAL (decl) != NULL_TREE) - DECL_INITIAL (decl) = error_mark_node; } else if (current_scope != file_scope) { @@ -4458,14 +4455,19 @@ grokdeclarator (const struct c_declarator *declarator, if (pedantic) pedwarn ("invalid storage class for function %qs", name); } - if (storage_class == csc_static) + else if (storage_class == csc_static) { error ("invalid storage class for function %qs", name); - if (DECL_INITIAL (decl) != NULL_TREE) - DECL_INITIAL (decl) = error_mark_node; + if (funcdef_flag) + storage_class = declspecs->storage_class = csc_none; + else + return 0; } } + decl = build_decl (FUNCTION_DECL, declarator->u.id, type); + decl = build_decl_attribute_variant (decl, decl_attr); + DECL_LANG_SPECIFIC (decl) = GGC_CNEW (struct lang_decl); if (pedantic && type_quals && !DECL_IN_SYSTEM_HEADER (decl)) diff --git a/gcc/c-parse.in b/gcc/c-parse.in index 86880ac6153..94df4bbc3b0 100644 --- a/gcc/c-parse.in +++ b/gcc/c-parse.in @@ -1321,16 +1321,23 @@ initdcl: declarator maybeasm maybe_attribute '=' { $<ttype>$ = start_decl ($1, current_declspecs, true, chainon ($3, all_prefix_attributes)); + if (!$<ttype>$) + $<ttype>$ = error_mark_node; start_init ($<ttype>$, $2, global_bindings_p ()); } init /* Note how the declaration of the variable is in effect while its init is parsed! */ { finish_init (); - maybe_warn_string_init (TREE_TYPE ($<ttype>5), $6); - finish_decl ($<ttype>5, $6.value, $2); } + if ($<ttype>5 != error_mark_node) + { + maybe_warn_string_init (TREE_TYPE ($<ttype>5), $6); + finish_decl ($<ttype>5, $6.value, $2); + } + } | declarator maybeasm maybe_attribute { tree d = start_decl ($1, current_declspecs, false, chainon ($3, all_prefix_attributes)); - finish_decl (d, NULL_TREE, $2); + if (d) + finish_decl (d, NULL_TREE, $2); } ; @@ -1338,16 +1345,23 @@ notype_initdcl: notype_declarator maybeasm maybe_attribute '=' { $<ttype>$ = start_decl ($1, current_declspecs, true, chainon ($3, all_prefix_attributes)); + if (!$<ttype>$) + $<ttype>$ = error_mark_node; start_init ($<ttype>$, $2, global_bindings_p ()); } init /* Note how the declaration of the variable is in effect while its init is parsed! */ { finish_init (); - maybe_warn_string_init (TREE_TYPE ($<ttype>5), $6); - finish_decl ($<ttype>5, $6.value, $2); } + if ($<ttype>5 != error_mark_node) + { + maybe_warn_string_init (TREE_TYPE ($<ttype>5), $6); + finish_decl ($<ttype>5, $6.value, $2); + } + } | notype_declarator maybeasm maybe_attribute { tree d = start_decl ($1, current_declspecs, false, chainon ($3, all_prefix_attributes)); - finish_decl (d, NULL_TREE, $2); } + if (d) + finish_decl (d, NULL_TREE, $2); } ; /* the * rules are dummies to accept the Apollo extended syntax so that the header files compile. */ diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index b3f18727585..d2963b37454 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -4470,7 +4470,7 @@ start_init (tree decl, tree asmspec_tree ATTRIBUTE_UNUSED, int top_level) constructor_designated = 0; constructor_top_level = top_level; - if (decl != 0) + if (decl != 0 && decl != error_mark_node) { require_constant_value = TREE_STATIC (decl); require_constant_elements diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 138785b2a89..0c742af3358 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2004-12-21 James A. Morrison <phython@gcc.gnu.org> + + PR c/18596 + * gcc.dg/funcdef-storage-1.c (foo): Remove. + * gcc.dg/pr18596-1.c: Use dg-error. + (dg-options): Use -fno-unit-at-a-time. + * gcc.dg/pr18596-2.c: New test. + * gcc.dg/pr18596-3.c: New test. + 2004-12-20 Roger Sayle <roger@eyesopen.com> PR middle-end/18683 diff --git a/gcc/testsuite/gcc.dg/funcdef-storage-1.c b/gcc/testsuite/gcc.dg/funcdef-storage-1.c index 7ced3a14b2e..9aa963a0288 100644 --- a/gcc/testsuite/gcc.dg/funcdef-storage-1.c +++ b/gcc/testsuite/gcc.dg/funcdef-storage-1.c @@ -1,5 +1,4 @@ /* { dg-do compile } */ -/* { dg-options "" } */ void flarm(void) @@ -8,8 +7,3 @@ flarm(void) foo(); } - -static void -foo(void) -{ -} diff --git a/gcc/testsuite/gcc.dg/pr18596-1.c b/gcc/testsuite/gcc.dg/pr18596-1.c index 055d60a4a75..dc34f444e5d 100644 --- a/gcc/testsuite/gcc.dg/pr18596-1.c +++ b/gcc/testsuite/gcc.dg/pr18596-1.c @@ -1,7 +1,39 @@ /* { dg-do compile } */ +/* { dg-options "-fno-unit-at-a-time" } */ + int f(int i) { - static int g(); /* { dg-warning "invalid storage class" } */ - static int g() { return i; } /* { dg-warning "invalid storage class" } */ + static int g(); /* { dg-error "invalid storage class" } */ + static int g() { return i; } /* { dg-error "invalid storage class" } */ return g(); } + +int k (int i) +{ + static int g (); /* { dg-error "invalid storage class" } */ + int g () { + return i; + } + + return g (); +} + +int l (int i) +{ + auto int g (); + static int g () { /* { dg-error "invalid storage class" } */ + return i; + } + + static int h () { /* { dg-error "invalid storage class" } */ + return 3; + } + return g () + h (); +} + +int m (int i) +{ + static g (); /* { dg-error "invalid storage class" } */ + static g () { return i; } /* { dg-error "invalid storage class" } */ + return g (); +} diff --git a/gcc/testsuite/gcc.dg/pr18596-2.c b/gcc/testsuite/gcc.dg/pr18596-2.c new file mode 100644 index 00000000000..7a52e807d38 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr18596-2.c @@ -0,0 +1,39 @@ +/* { dg-do compile } */ +/* { dg-options "-funit-at-a-time" } */ + +int f(int i) +{ + static int g(); /* { dg-error "invalid storage class" } */ + static int g() { return i; } /* { dg-error "invalid storage class" } */ + return g(); +} + +int k (int i) +{ + static int g (); /* { dg-error "invalid storage class" } */ + int g () { + return i; + } + + return g (); +} + +int l (int i) +{ + auto int g (); + static int g () { /* { dg-error "invalid storage class" } */ + return i; + } + + static int h () { /* { dg-error "invalid storage class" } */ + return 3; + } + return g () + h (); +} + +int m (int i) +{ + static g (); /* { dg-error "invalid storage class" } */ + static g () { return i; } /* { dg-error "invalid storage class" } */ + return g (); +} diff --git a/gcc/testsuite/gcc.dg/pr18596-3.c b/gcc/testsuite/gcc.dg/pr18596-3.c new file mode 100644 index 00000000000..be17e7ca4b3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr18596-3.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "" } */ + +int foo () +{ + static g () = 0; /* { dg-error "invalid storage class" } */ + static int f () = 1; /* { dg-error "invalid storage class" } */ + auto int h () = 0; /* { dg-error "initialized like a variable" } */ + static int i () = { 0 }; /* { dg-error "invalid storage class" } */ + static int j () = /* { dg-error "invalid storage class" } */ + { 0, 0.0 }; +} +/* { dg-warning "excess elements" "" { target *-*-* } 11 } */ +/* { dg-warning "near initialization" "" { target *-*-* } 11 } */ |