diff options
author | Joseph Myers <jsm28@cam.ac.uk> | 2001-12-03 00:09:34 +0000 |
---|---|---|
committer | Joseph Myers <jsm28@gcc.gnu.org> | 2001-12-03 00:09:34 +0000 |
commit | 39bc99c26599afa6f3a8bfe0710b11e00b00365b (patch) | |
tree | be5d4e7771afbef3ccf72b8f9c94878ef8323adc | |
parent | 671f5733ffa12a8b7d7a7f01e1c734a122217b4a (diff) | |
download | gcc-39bc99c26599afa6f3a8bfe0710b11e00b00365b.zip gcc-39bc99c26599afa6f3a8bfe0710b11e00b00365b.tar.gz gcc-39bc99c26599afa6f3a8bfe0710b11e00b00365b.tar.bz2 |
c-typeck.c (really_start_incremental_init, [...]): Avoid constructor_max_index being other than an INTEGER_CST.
* c-typeck.c (really_start_incremental_init, push_init_level):
Avoid constructor_max_index being other than an INTEGER_CST.
testsuite:
* gcc.dg/vla-init-1.c: New test.
From-SVN: r47539
-rw-r--r-- | gcc/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/c-typeck.c | 14 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/vla-init-1.c | 13 |
4 files changed, 36 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c107502..12fba08 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2001-12-03 Joseph S. Myers <jsm28@cam.ac.uk> + + * c-typeck.c (really_start_incremental_init, push_init_level): + Avoid constructor_max_index being other than an INTEGER_CST. + 2001-12-02 David Edelsohn <edelsohn@gnu.org> * config/rs6000/xcoff.h (ASM_OUTPUT_INTERNAL_LABEL): Display count diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 64f0f07..ff504dc 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -5259,6 +5259,13 @@ really_start_incremental_init (type) && TYPE_SIZE (constructor_type)) constructor_max_index = build_int_2 (-1, -1); + /* constructor_max_index needs to be an INTEGER_CST. Attempts + to initialize VLAs will cause an proper error; avoid tree + checking errors as well by setting a safe value. */ + if (constructor_max_index + && TREE_CODE (constructor_max_index) != INTEGER_CST) + constructor_max_index = build_int_2 (-1, -1); + constructor_index = convert (bitsizetype, TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type))); @@ -5426,6 +5433,13 @@ push_init_level (implicit) && TYPE_SIZE (constructor_type)) constructor_max_index = build_int_2 (-1, -1); + /* constructor_max_index needs to be an INTEGER_CST. Attempts + to initialize VLAs will cause an proper error; avoid tree + checking errors as well by setting a safe value. */ + if (constructor_max_index + && TREE_CODE (constructor_max_index) != INTEGER_CST) + constructor_max_index = build_int_2 (-1, -1); + constructor_index = convert (bitsizetype, TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type))); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d3a4df6..7f71389 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2001-12-03 Joseph S. Myers <jsm28@cam.ac.uk> + + * gcc.dg/vla-init-1.c: New test. + 2001-12-01 Geoff Keating <geoffk@redhat.com> * gcc.c-torture/compile/structs.c: New testcase from GDB. diff --git a/gcc/testsuite/gcc.dg/vla-init-1.c b/gcc/testsuite/gcc.dg/vla-init-1.c new file mode 100644 index 0000000..61d2357 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vla-init-1.c @@ -0,0 +1,13 @@ +/* Test for tree-checking error when initializing a variable-length array + (not allowed): constructor_max_index needs to be an INTEGER_CST. */ +/* Origin: Joseph Myers <jsm28@cam.ac.uk>. */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +int a; + +void +foo (void) +{ + int x[a] = { 1 }; /* { dg-error "init" "VLA init" } */ +} |