diff options
author | jsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4> | 2009-04-24 17:24:32 +0000 |
---|---|---|
committer | jsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4> | 2009-04-24 17:24:32 +0000 |
commit | 88c32270aa798c7e60d83f97eb456a440c7db5db (patch) | |
tree | a6300e7d88299fc54fd9ad19a6c84f9e22ccfa43 | |
parent | 5daf45f29a68366981a30dc0deb3dae9b494d5ba (diff) | |
download | ppe42-gcc-88c32270aa798c7e60d83f97eb456a440c7db5db.tar.gz ppe42-gcc-88c32270aa798c7e60d83f97eb456a440c7db5db.zip |
* c-typeck.c (set_init_index): Allow array designators that are
not integer constant expressions with a pedwarn if pedantic.
testsuite:
* gcc.dg/array-const-1.c, gcc.dg/array-const-2.c,
gcc.dg/array-const-3.c: New tests.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@146741 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/c-typeck.c | 18 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/array-const-1.c | 8 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/array-const-2.c | 9 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/array-const-3.c | 9 |
6 files changed, 54 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a48db46dcd5..51d848d755b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2009-04-24 Joseph Myers <joseph@codesourcery.com> + + * c-typeck.c (set_init_index): Allow array designators that are + not integer constant expressions with a pedwarn if pedantic. + 2009-04-24 Bernd Schmidt <bernd.schmidt@analog.com> * simplify-rtx.c (simplify_binary_operation_1, case AND): Result is diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index c7ea3284ac0..1cfab1f14f2 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -6422,6 +6422,24 @@ set_init_index (tree first, tree last) } if (TREE_CODE (first) != INTEGER_CST) + { + first = c_fully_fold (first, false, NULL); + if (TREE_CODE (first) == INTEGER_CST) + pedwarn_init (input_location, OPT_pedantic, + "array index in initializer is not " + "an integer constant expression"); + } + + if (last && TREE_CODE (last) != INTEGER_CST) + { + last = c_fully_fold (last, false, NULL); + if (TREE_CODE (last) == INTEGER_CST) + pedwarn_init (input_location, OPT_pedantic, + "array index in initializer is not " + "an integer constant expression"); + } + + if (TREE_CODE (first) != INTEGER_CST) error_init ("nonconstant array index in initializer"); else if (last != 0 && TREE_CODE (last) != INTEGER_CST) error_init ("nonconstant array index in initializer"); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b4ec0dd5cac..083a7e3efa5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2009-04-24 Joseph Myers <joseph@codesourcery.com> + + * gcc.dg/array-const-1.c, gcc.dg/array-const-2.c, + gcc.dg/array-const-3.c: New tests. + 2009-04-24 Ian Lance Taylor <iant@google.com> * gcc.dg/Wcxx-compat-4.c: New testcase. diff --git a/gcc/testsuite/gcc.dg/array-const-1.c b/gcc/testsuite/gcc.dg/array-const-1.c new file mode 100644 index 00000000000..0e0c46224cf --- /dev/null +++ b/gcc/testsuite/gcc.dg/array-const-1.c @@ -0,0 +1,8 @@ +/* Test for array designators not integer constant expressions but + folding to integer constants (used in Linux kernel, + <http://gcc.gnu.org/ml/gcc/2009-04/msg00611.html>). */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99" } */ + +extern int i; +int a[] = { [1 ? 1 : i] = 0 }; diff --git a/gcc/testsuite/gcc.dg/array-const-2.c b/gcc/testsuite/gcc.dg/array-const-2.c new file mode 100644 index 00000000000..f6e2bd5bbfa --- /dev/null +++ b/gcc/testsuite/gcc.dg/array-const-2.c @@ -0,0 +1,9 @@ +/* Test for array designators not integer constant expressions but + folding to integer constants (used in Linux kernel, + <http://gcc.gnu.org/ml/gcc/2009-04/msg00611.html>). */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -pedantic" } */ + +extern int i; +int a[] = { [1 ? 1 : i] = 0 }; /* { dg-warning "array index in initializer is not an integer constant expression" } */ +/* { dg-warning "near initialization" "near init" { target *-*-* } 8 } */ diff --git a/gcc/testsuite/gcc.dg/array-const-3.c b/gcc/testsuite/gcc.dg/array-const-3.c new file mode 100644 index 00000000000..5bb215cbd0f --- /dev/null +++ b/gcc/testsuite/gcc.dg/array-const-3.c @@ -0,0 +1,9 @@ +/* Test for array designators not integer constant expressions but + folding to integer constants (used in Linux kernel, + <http://gcc.gnu.org/ml/gcc/2009-04/msg00611.html>). */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -pedantic-errors" } */ + +extern int i; +int a[] = { [1 ? 1 : i] = 0 }; /* { dg-error "array index in initializer is not an integer constant expression" } */ +/* { dg-error "near initialization" "near init" { target *-*-* } 8 } */ |