re PR c++/57402 (ICE: in make_decl_rtl, at varasm.c:1147 when initializing variable...
authorJason Merrill <jason@redhat.com>
Wed, 10 Jul 2013 00:37:49 +0000 (20:37 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 10 Jul 2013 00:37:49 +0000 (20:37 -0400)
PR c++/57402
* init.c (build_vec_init): Don't take shortcuts when initializing
a VLA.

From-SVN: r200860

gcc/cp/ChangeLog
gcc/cp/init.c
gcc/testsuite/g++.dg/cpp1y/vla10.C [new file with mode: 0644]

index 1bc0b6f88c64fc1da0fc96eab0ce6b4e9d2680e0..7da759a6c9d2615b4b535d2513e322cdcffd7c59 100644 (file)
@@ -1,5 +1,9 @@
 2013-07-09  Jason Merrill  <jason@redhat.com>
 
+       PR c++/57402
+       * init.c (build_vec_init): Don't take shortcuts when initializing
+       a VLA.
+
        PR c++/57471
        * parser.c (cp_parser_sizeof_pack): Clear parser scopes.
 
index 4edd150d91360b3d3b22fda5d6619bf9fb92c462..7acc7b582fecfa7be41deed3ef88a125e69fb1ea 100644 (file)
@@ -3332,6 +3332,7 @@ build_vec_init (tree base, tree maxindex, tree init,
 
   if (init
       && TREE_CODE (atype) == ARRAY_TYPE
+      && TREE_CONSTANT (maxindex)
       && (from_array == 2
          ? (!CLASS_TYPE_P (inner_elt_type)
             || !TYPE_HAS_COMPLEX_COPY_ASSIGN (inner_elt_type))
@@ -3452,6 +3453,7 @@ build_vec_init (tree base, tree maxindex, tree init,
       tree field, elt;
       /* Should we try to create a constant initializer?  */
       bool try_const = (TREE_CODE (atype) == ARRAY_TYPE
+                       && TREE_CONSTANT (maxindex)
                        && (literal_type_p (inner_elt_type)
                            || TYPE_HAS_CONSTEXPR_CTOR (inner_elt_type)));
       /* If the constructor already has the array type, it's been through
@@ -3561,6 +3563,8 @@ build_vec_init (tree base, tree maxindex, tree init,
 
       /* Clear out INIT so that we don't get confused below.  */
       init = NULL_TREE;
+      /* Any elements without explicit initializers get {}.  */
+      explicit_value_init_p = true;
     }
   else if (from_array)
     {
diff --git a/gcc/testsuite/g++.dg/cpp1y/vla10.C b/gcc/testsuite/g++.dg/cpp1y/vla10.C
new file mode 100644 (file)
index 0000000..1c67290
--- /dev/null
@@ -0,0 +1,24 @@
+// PR c++/57402
+// { dg-options "-std=c++1y -pedantic-errors" }
+
+int i = 2;
+
+int main()
+{
+  {
+    int a[i];
+    a[1] = 0xbeef;
+  }
+  {
+    int a[i] = { 1 };
+    if (a[1] != 0)
+      __builtin_abort ();
+    a[1] = 0xbeef;
+  }
+  {
+    int a[i] = { };
+    if (a[1] != 0)
+      __builtin_abort ();
+    a[1] = 0xbeef;
+  }
+}