mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-04-21 14:50:57 +08:00
re PR c/16409 (ICE in size_binop, at fold-const.c)
PR c/16409 * c-decl.c (start_decl): Check for initializing incomplete array of VLAs. (build_compound_literal): Check for TYPE being error_mark_node. * c-parse.in (primary): Check for VLA compound literals. testsuite: * gcc.dg/vla-init-2.c, gcc.dg/vla-init-3.c, gcc.dg/vla-init-4.c, gcc.dg/vla-init-5.c: New tests. From-SVN: r88248
This commit is contained in:
parent
346c5b01de
commit
ef7878226a
@ -1,3 +1,11 @@
|
||||
2004-09-28 Joseph S. Myers <jsm@polyomino.org.uk>
|
||||
|
||||
PR c/16409
|
||||
* c-decl.c (start_decl): Check for initializing incomplete array
|
||||
of VLAs.
|
||||
(build_compound_literal): Check for TYPE being error_mark_node.
|
||||
* c-parse.in (primary): Check for VLA compound literals.
|
||||
|
||||
2004-09-28 Diego Novillo <dnovillo@redhat.com>
|
||||
|
||||
* tree-ssa-live.c (calculate_live_on_entry): Fix warnings
|
||||
|
16
gcc/c-decl.c
16
gcc/c-decl.c
@ -2986,6 +2986,15 @@ start_decl (struct c_declarator *declarator, struct c_declspecs *declspecs,
|
||||
error ("elements of array %qD have incomplete type", decl);
|
||||
initialized = 0;
|
||||
}
|
||||
else if (C_DECL_VARIABLE_SIZE (decl))
|
||||
{
|
||||
/* Although C99 is unclear about whether incomplete arrays
|
||||
of VLAs themselves count as VLAs, it does not make
|
||||
sense to permit them to be initialized given that
|
||||
ordinary VLAs may not be initialized. */
|
||||
error ("variable-sized object may not be initialized");
|
||||
initialized = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (initialized)
|
||||
@ -3416,9 +3425,14 @@ build_compound_literal (tree type, tree init)
|
||||
/* We do not use start_decl here because we have a type, not a declarator;
|
||||
and do not use finish_decl because the decl should be stored inside
|
||||
the COMPOUND_LITERAL_EXPR rather than added elsewhere as a DECL_EXPR. */
|
||||
tree decl = build_decl (VAR_DECL, NULL_TREE, type);
|
||||
tree decl;
|
||||
tree complit;
|
||||
tree stmt;
|
||||
|
||||
if (type == error_mark_node)
|
||||
return error_mark_node;
|
||||
|
||||
decl = build_decl (VAR_DECL, NULL_TREE, type);
|
||||
DECL_EXTERNAL (decl) = 0;
|
||||
TREE_PUBLIC (decl) = 0;
|
||||
TREE_STATIC (decl) = (current_scope == file_scope);
|
||||
|
@ -677,6 +677,11 @@ primary:
|
||||
| '(' typename ')' '{'
|
||||
{ start_init (NULL_TREE, NULL, 0);
|
||||
$<ttype>$ = groktypename ($2);
|
||||
if (C_TYPE_VARIABLE_SIZE ($<ttype>$))
|
||||
{
|
||||
error ("compound literal has variable size");
|
||||
$<ttype>$ = error_mark_node;
|
||||
}
|
||||
really_start_incremental_init ($<ttype>$); }
|
||||
initlist_maybe_comma '}' %prec UNARY
|
||||
{ struct c_expr init = pop_init_level (0);
|
||||
|
@ -1,3 +1,9 @@
|
||||
2004-09-28 Joseph S. Myers <jsm@polyomino.org.uk>
|
||||
|
||||
PR c/16409
|
||||
* gcc.dg/vla-init-2.c, gcc.dg/vla-init-3.c, gcc.dg/vla-init-4.c,
|
||||
gcc.dg/vla-init-5.c: New tests.
|
||||
|
||||
2004-09-27 Joseph S. Myers <jsm@polyomino.org.uk>
|
||||
|
||||
PR c/13804
|
||||
|
10
gcc/testsuite/gcc.dg/vla-init-2.c
Normal file
10
gcc/testsuite/gcc.dg/vla-init-2.c
Normal file
@ -0,0 +1,10 @@
|
||||
/* Arrays of unknown size with element type a VLA type should not be
|
||||
initialized (C99 isn't clear about whether such arrays are VLAs,
|
||||
but this is the only reasonable interpretation). Bug 16409, first
|
||||
testcase. */
|
||||
/* { dg-do compile } */
|
||||
/* { dg-options "" } */
|
||||
|
||||
const int i = 1;
|
||||
void foo() { char a[][i] = {""}; } /* { dg-error "error: variable-sized object may not be initialized" } */
|
||||
/* { dg-error "array size missing in 'a'" "extra error" { target *-*-* } 9 } */
|
9
gcc/testsuite/gcc.dg/vla-init-3.c
Normal file
9
gcc/testsuite/gcc.dg/vla-init-3.c
Normal file
@ -0,0 +1,9 @@
|
||||
/* Arrays of unknown size with element type a VLA type should not be
|
||||
initialized (C99 isn't clear about whether such arrays are VLAs,
|
||||
but this is the only reasonable interpretation). Bug 16409, second
|
||||
testcase. */
|
||||
/* { dg-do compile } */
|
||||
/* { dg-options "" } */
|
||||
|
||||
void foo(int i) { char a[][i] = {""}; } /* { dg-error "error: variable-sized object may not be initialized" } */
|
||||
/* { dg-error "array size missing in 'a'" "extra error" { target *-*-* } 8 } */
|
7
gcc/testsuite/gcc.dg/vla-init-4.c
Normal file
7
gcc/testsuite/gcc.dg/vla-init-4.c
Normal file
@ -0,0 +1,7 @@
|
||||
/* Test for ICE on VLA compound literal. */
|
||||
/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
|
||||
/* { dg-do compile } */
|
||||
/* { dg-options "" } */
|
||||
|
||||
const int i = 1;
|
||||
void foo() { char *p = (char [i]){ "" }; } /* { dg-error "error: compound literal has variable size" } */
|
7
gcc/testsuite/gcc.dg/vla-init-5.c
Normal file
7
gcc/testsuite/gcc.dg/vla-init-5.c
Normal file
@ -0,0 +1,7 @@
|
||||
/* Test for ICE on incomplete-array-of-VLA compound literal. */
|
||||
/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
|
||||
/* { dg-do compile } */
|
||||
/* { dg-options "" } */
|
||||
|
||||
const int i = 1;
|
||||
void foo() { void *p = (char [][i]){ "" }; } /* { dg-error "error: compound literal has variable size" } */
|
Loading…
x
Reference in New Issue
Block a user