From 3542a5c0f694a66f6e126b71a668c51a87f609f3 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Sat, 9 Sep 2006 00:41:21 +0100 Subject: [PATCH] re PR c/28504 (ICE with variable sized array) PR c/28504 * c-tree.h (struct c_arg_info): Add pending_sizes. * c-parser.c (c_parser_parms_declarator, c_parser_parms_list_declarator): Initialize pending_sizes. * c-decl.c (get_parm_info): Initialize pending_sizes. (get_parm_info): Set pending_sizes. (grokdeclarator): Call put_pending_sizes for parameters for function definition only. testsuite: * gcc.dg/vla-10.c: New test. From-SVN: r116789 --- gcc/ChangeLog | 11 +++++++++++ gcc/c-decl.c | 4 ++++ gcc/c-parser.c | 5 +++++ gcc/c-tree.h | 5 +++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/vla-10.c | 7 +++++++ 6 files changed, 37 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/vla-10.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index baa8adc2962d..e4d586105e0d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,14 @@ +2006-09-08 Joseph S. Myers + + PR c/28504 + * c-tree.h (struct c_arg_info): Add pending_sizes. + * c-parser.c (c_parser_parms_declarator, + c_parser_parms_list_declarator): Initialize pending_sizes. + * c-decl.c (get_parm_info): Initialize pending_sizes. + (get_parm_info): Set pending_sizes. + (grokdeclarator): Call put_pending_sizes for parameters for + function definition only. + 2006-09-07 Jason Merrill PR middle-end/27724 diff --git a/gcc/c-decl.c b/gcc/c-decl.c index cf89191ae2e2..cbd356f9cefd 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -4420,6 +4420,8 @@ grokdeclarator (const struct c_declarator *declarator, inner layer of declarator. */ arg_info = declarator->u.arg_info; arg_types = grokparms (arg_info, really_funcdef); + if (really_funcdef) + put_pending_sizes (arg_info->pending_sizes); /* Type qualifiers before the return type of the function qualify the return type, not the function type. */ @@ -4981,6 +4983,7 @@ get_parm_info (bool ellipsis) arg_info->tags = 0; arg_info->types = 0; arg_info->others = 0; + arg_info->pending_sizes = 0; arg_info->had_vla_unspec = current_scope->had_vla_unspec; /* The bindings in this scope must not get put into a block. @@ -5136,6 +5139,7 @@ get_parm_info (bool ellipsis) arg_info->tags = tags; arg_info->types = types; arg_info->others = others; + arg_info->pending_sizes = get_pending_sizes (); return arg_info; } diff --git a/gcc/c-parser.c b/gcc/c-parser.c index 9031e5b4d2f2..852025392833 100644 --- a/gcc/c-parser.c +++ b/gcc/c-parser.c @@ -2537,6 +2537,7 @@ c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs) ret->tags = 0; ret->types = list; ret->others = 0; + ret->pending_sizes = 0; ret->had_vla_unspec = 0; c_parser_consume_token (parser); pop_scope (); @@ -2579,6 +2580,7 @@ c_parser_parms_list_declarator (c_parser *parser, tree attrs) ret->tags = 0; ret->types = 0; ret->others = 0; + ret->pending_sizes = 0; ret->had_vla_unspec = 0; c_parser_consume_token (parser); return ret; @@ -2589,6 +2591,7 @@ c_parser_parms_list_declarator (c_parser *parser, tree attrs) ret->parms = 0; ret->tags = 0; ret->others = 0; + ret->pending_sizes = 0; ret->had_vla_unspec = 0; /* Suppress -Wold-style-definition for this case. */ ret->types = error_mark_node; @@ -2640,6 +2643,7 @@ c_parser_parms_list_declarator (c_parser *parser, tree attrs) ret->tags = 0; ret->types = 0; ret->others = 0; + ret->pending_sizes = 0; ret->had_vla_unspec = 0; return ret; } @@ -2666,6 +2670,7 @@ c_parser_parms_list_declarator (c_parser *parser, tree attrs) ret->tags = 0; ret->types = 0; ret->others = 0; + ret->pending_sizes = 0; ret->had_vla_unspec = 0; return ret; } diff --git a/gcc/c-tree.h b/gcc/c-tree.h index 3503c793a231..79579b0547a6 100644 --- a/gcc/c-tree.h +++ b/gcc/c-tree.h @@ -309,6 +309,11 @@ struct c_arg_info { /* A list of non-parameter decls (notably enumeration constants) defined with the parameters. */ tree others; + /* A list of VLA sizes from the parameters. In a function + definition, these are used to ensure that side-effects in sizes + of arrays converted to pointers (such as a parameter int i[n++]) + take place; otherwise, they are ignored. */ + tree pending_sizes; /* True when these arguments had [*]. */ BOOL_BITFIELD had_vla_unspec : 1; }; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index eb350af57410..0ba42158ca3f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2006-09-08 Joseph S. Myers + + PR c/28504 + * gcc.dg/vla-10.c: New test. + 2006-09-08 Volker Reichelt PR c++/28858 diff --git a/gcc/testsuite/gcc.dg/vla-10.c b/gcc/testsuite/gcc.dg/vla-10.c new file mode 100644 index 000000000000..47dff47c55f3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vla-10.c @@ -0,0 +1,7 @@ +/* ICE with VLA in nested parameter declaration: should be treated + like [*] instead of the size being expanded. Bug 28504 from Volker + Reichelt . */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +void foo(void (*p)(int n, int x[n])) {}