diff options
author | Joseph Myers <joseph@codesourcery.com> | 2013-11-29 21:24:14 +0000 |
---|---|---|
committer | Joseph Myers <jsm28@gcc.gnu.org> | 2013-11-29 21:24:14 +0000 |
commit | 340baef702ea62dfcdc8003ff9c4f4c2bd8322fb (patch) | |
tree | 7572bf13617b1296fdbc55a439078a888540dc4b | |
parent | 3163a5cab5300b83bc261da596a2301431505909 (diff) | |
download | gcc-340baef702ea62dfcdc8003ff9c4f4c2bd8322fb.zip gcc-340baef702ea62dfcdc8003ff9c4f4c2bd8322fb.tar.gz gcc-340baef702ea62dfcdc8003ff9c4f4c2bd8322fb.tar.bz2 |
re PR c/42262 (internal compiler error: in set_designator, at c-typeck.c:5771)
PR c/42262
c:
* c-typeck.c (process_init_element): Do not treat a string as
initializing a whole array when used with a designator for an
individual element.
testsuite:
* gcc.dg/c99-init-5.c, gcc.dg/c99-init-6.c: New tests.
From-SVN: r205543
-rw-r--r-- | gcc/c/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/c/c-typeck.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/c99-init-5.c | 9 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/c99-init-6.c | 6 |
5 files changed, 29 insertions, 0 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 7016ecb..a106e64 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,5 +1,12 @@ 2013-11-29 Joseph Myers <joseph@codesourcery.com> + PR c/42262 + * c-typeck.c (process_init_element): Do not treat a string as + initializing a whole array when used with a designator for an + individual element. + +2013-11-29 Joseph Myers <joseph@codesourcery.com> + PR c/57574 * c-decl.c (merge_decls): Clear DECL_EXTERNAL for a definition of an inline function following a static declaration. diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index f602ca4..4d70104 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -8504,6 +8504,7 @@ process_init_element (struct c_expr value, bool implicit, tree orig_value = value.value; int string_flag = orig_value != 0 && TREE_CODE (orig_value) == STRING_CST; bool strict_string = value.original_code == STRING_CST; + bool was_designated = designator_depth != 0; designator_depth = 0; designator_erroneous = 0; @@ -8512,6 +8513,7 @@ process_init_element (struct c_expr value, bool implicit, char x[] = {"foo"}; */ if (string_flag && constructor_type + && !was_designated && TREE_CODE (constructor_type) == ARRAY_TYPE && INTEGRAL_TYPE_P (TREE_TYPE (constructor_type)) && integer_zerop (constructor_unfilled_index)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3f13f64..f3f6102 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2013-11-29 Joseph Myers <joseph@codesourcery.com> + + PR c/42262 + * gcc.dg/c99-init-5.c, gcc.dg/c99-init-6.c: New tests. + 2013-11-29 H.J. Lu <hongjiu.lu@intel.com> * lib/asan-dg.exp (asan_link_flags): Properly add path to diff --git a/gcc/testsuite/gcc.dg/c99-init-5.c b/gcc/testsuite/gcc.dg/c99-init-5.c new file mode 100644 index 0000000..17bacd9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c99-init-5.c @@ -0,0 +1,9 @@ +/* Test for designated initializers: string constants used with + designator in character array should not initialize the array as a + whole. */ +/* { dg-do compile } */ +/* { dg-options "-std=iso9899:1999 -pedantic-errors" } */ + +char g[] = { [7] = "abcd" }; /* { dg-error "initial" } */ +char h[10][10] = { [1][1] = "abcd" }; /* { dg-error "initial" } */ +char i[10][10] = { [1] = "abcd" }; diff --git a/gcc/testsuite/gcc.dg/c99-init-6.c b/gcc/testsuite/gcc.dg/c99-init-6.c new file mode 100644 index 0000000..6328f82 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c99-init-6.c @@ -0,0 +1,6 @@ +/* Test for designated initializers: invalid uses of string constants + should not ICE. PR 42262. */ +/* { dg-do compile } */ +/* { dg-options "-std=iso9899:1999 -pedantic-errors" } */ + +int a[] = { [0 ... 1] = "", [0] = "" }; /* { dg-error "initial" } */ |