aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2013-07-09 20:37:49 -0400
committerJason Merrill <jason@gcc.gnu.org>2013-07-09 20:37:49 -0400
commit06b76c7fa890d60d0828f2c3b1757fe7497e3786 (patch)
tree4fc08e664828c81326a1f3e0668ab14b25d1aaac
parent9be2cb3797ab8fcbf9fec73c8485f2e106b1dbaa (diff)
downloadgcc-06b76c7fa890d60d0828f2c3b1757fe7497e3786.zip
gcc-06b76c7fa890d60d0828f2c3b1757fe7497e3786.tar.gz
gcc-06b76c7fa890d60d0828f2c3b1757fe7497e3786.tar.bz2
re PR c++/57402 (ICE: in make_decl_rtl, at varasm.c:1147 when initializing variable-sized array)
PR c++/57402 * init.c (build_vec_init): Don't take shortcuts when initializing a VLA. From-SVN: r200860
-rw-r--r--gcc/cp/ChangeLog4
-rw-r--r--gcc/cp/init.c4
-rw-r--r--gcc/testsuite/g++.dg/cpp1y/vla10.C24
3 files changed, 32 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 1bc0b6f..7da759a 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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.
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 4edd150..7acc7b5 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -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
index 0000000..1c67290
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/vla10.C
@@ -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;
+ }
+}