diff options
author | David Pagan <dave.pagan@oracle.com> | 2018-05-02 17:22:26 +0000 |
---|---|---|
committer | Jeff Law <law@gcc.gnu.org> | 2018-05-02 11:22:26 -0600 |
commit | f7584c811623675be258da5195d8e8daeb562975 (patch) | |
tree | efbf7e13707325d8fd0fe006a25ea5ece053f911 /gcc/c | |
parent | 621af561737ae17f6b4cffad9b79b1189503f011 (diff) | |
download | gcc-f7584c811623675be258da5195d8e8daeb562975.zip gcc-f7584c811623675be258da5195d8e8daeb562975.tar.gz gcc-f7584c811623675be258da5195d8e8daeb562975.tar.bz2 |
re PR c/30552 (gcc crashes when compiling examples with GNU statement expressions in VLAs (also involved: nested functions declared K&R-style))
PR c/30552
* c-decl.c (old_style_parameter_scope): New function.
* c-parser.c (c_parser_postfix_expression): Check for statement
expressions in old-style function parameter list declarations.
* c-parser.h (old_style_parameter_scope): New extern declaration.
PR c/30552
* gcc.dg/noncompile/pr30552-1.c: New test.
* gcc.dg/noncompile/pr30552-2.c: New test.
* gcc.dg/noncompile/pr30552-3.c: New test.
* gcc.dg/noncompile/pr30552-4.c: New test.
From-SVN: r259849
Diffstat (limited to 'gcc/c')
-rw-r--r-- | gcc/c/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/c/c-decl.c | 11 | ||||
-rw-r--r-- | gcc/c/c-parser.c | 5 | ||||
-rw-r--r-- | gcc/c/c-parser.h | 3 |
4 files changed, 26 insertions, 1 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 7a3cf3f..d88d70d 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,11 @@ +2018-05-02 David Pagan <dave.pagan@oracle.com> + + PR c/30552 + * c-decl.c (old_style_parameter_scope): New function. + * c-parser.c (c_parser_postfix_expression): Check for statement + expressions in old-style function parameter list declarations. + * c-parser.h (old_style_parameter_scope): New extern declaration. + 2018-04-25 Jakub Jelinek <jakub@redhat.com> PR sanitizer/84307 diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 7255588..3c4b18e 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -952,6 +952,17 @@ global_bindings_p (void) return current_scope == file_scope; } +/* Return true if we're declaring parameters in an old-style function + declaration. */ + +bool +old_style_parameter_scope (void) +{ + /* If processing parameters and there is no function statement list, we + * have an old-style function declaration. */ + return (current_scope->parm_flag && !DECL_SAVED_TREE (current_function_decl)); +} + void keep_next_level (void) { diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index 4772086..6b41a61 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -7930,7 +7930,10 @@ c_parser_postfix_expression (c_parser *parser) c_parser_consume_token (parser); brace_loc = c_parser_peek_token (parser)->location; c_parser_consume_token (parser); - if (!building_stmt_list_p ()) + /* If we've not yet started the current function's statement list, + or we're in the parameter scope of an old-style function + declaration, statement expressions are not allowed. */ + if (!building_stmt_list_p () || old_style_parameter_scope ()) { error_at (loc, "braced-group within expression allowed " "only inside a function"); diff --git a/gcc/c/c-parser.h b/gcc/c/c-parser.h index da77f68..c9d38ac 100644 --- a/gcc/c/c-parser.h +++ b/gcc/c/c-parser.h @@ -155,6 +155,9 @@ extern c_token * c_parser_tokens_buf (c_parser *parser, unsigned n); extern bool c_parser_error (c_parser *parser); extern void c_parser_set_error (c_parser *parser, bool); +/* A bit of a hack to have this here. It would be better in a c-decl.h. */ +extern bool old_style_parameter_scope (void); + /* Return true if the next token from PARSER has the indicated TYPE. */ |