]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c/42262 (internal compiler error: in set_designator, at c-typeck.c:5771)
authorJoseph Myers <joseph@codesourcery.com>
Fri, 29 Nov 2013 21:24:14 +0000 (21:24 +0000)
committerJoseph Myers <jsm28@gcc.gnu.org>
Fri, 29 Nov 2013 21:24:14 +0000 (21:24 +0000)
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

gcc/c/ChangeLog
gcc/c/c-typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/c99-init-5.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/c99-init-6.c [new file with mode: 0644]

index 7016ecb4bf9f9f2169a93de7ba626c01de57d1e3..a106e64d094a03d79b76adbb392ecf3006e86b7c 100644 (file)
@@ -1,3 +1,10 @@
+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
index f602ca4eb544fd79c239731789dcfa36bfc5806b..4d701045309a2e24adde0c41234a408608040e16 100644 (file)
@@ -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))
index 3f13f64245cb9d9c5370eaee36d4a9158efeaf8d..f3f610276331468cab74f12e97980abbdb7bef40 100644 (file)
@@ -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 (file)
index 0000000..17bacd9
--- /dev/null
@@ -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 (file)
index 0000000..6328f82
--- /dev/null
@@ -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" } */