From 06b76c7fa890d60d0828f2c3b1757fe7497e3786 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Tue, 9 Jul 2013 20:37:49 -0400 Subject: [PATCH] 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 --- gcc/cp/ChangeLog | 4 ++++ gcc/cp/init.c | 4 ++++ gcc/testsuite/g++.dg/cpp1y/vla10.C | 24 ++++++++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp1y/vla10.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 1bc0b6f88c6..7da759a6c9d 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2013-07-09 Jason Merrill + 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 4edd150d913..7acc7b582fe 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 00000000000..1c672903092 --- /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; + } +} -- 2.30.2