Commit fe217ba0 by Jakub Jelinek Committed by Jakub Jelinek

re PR c++/84808 (ICE with constexpr and array)

	PR c++/84808
	* constexpr.c (find_array_ctor_elt): Don't use elt reference after
	first potential CONSTRUCTOR_ELTS reallocation.  Convert dindex to
	sizetype.  Formatting fixes.

	* g++.dg/cpp1y/constexpr-84808.C: New test.

From-SVN: r258471
parent 038df1ba
2018-03-13 Jakub Jelinek <jakub@redhat.com>
PR c++/84808
* constexpr.c (find_array_ctor_elt): Don't use elt reference after
first potential CONSTRUCTOR_ELTS reallocation. Convert dindex to
sizetype. Formatting fixes.
2018-03-12 Jason Merrill <jason@redhat.com> 2018-03-12 Jason Merrill <jason@redhat.com>
PR c++/84355 - ICE with deduction for member class template. PR c++/84355 - ICE with deduction for member class template.
......
...@@ -2194,9 +2194,9 @@ find_array_ctor_elt (tree ary, tree dindex, bool insert = false) ...@@ -2194,9 +2194,9 @@ find_array_ctor_elt (tree ary, tree dindex, bool insert = false)
that the same is true of the other elements and index directly. */ that the same is true of the other elements and index directly. */
if (end > 0) if (end > 0)
{ {
tree cindex = (*elts)[end-1].index; tree cindex = (*elts)[end - 1].index;
if (TREE_CODE (cindex) == INTEGER_CST if (TREE_CODE (cindex) == INTEGER_CST
&& compare_tree_int (cindex, end-1) == 0) && compare_tree_int (cindex, end - 1) == 0)
{ {
if (i < end) if (i < end)
return i; return i;
...@@ -2225,6 +2225,8 @@ find_array_ctor_elt (tree ary, tree dindex, bool insert = false) ...@@ -2225,6 +2225,8 @@ find_array_ctor_elt (tree ary, tree dindex, bool insert = false)
constructor_elt e; constructor_elt e;
tree lo = TREE_OPERAND (idx, 0); tree lo = TREE_OPERAND (idx, 0);
tree hi = TREE_OPERAND (idx, 1); tree hi = TREE_OPERAND (idx, 1);
tree value = elt.value;
dindex = fold_convert (sizetype, dindex);
if (tree_int_cst_lt (lo, dindex)) if (tree_int_cst_lt (lo, dindex))
{ {
/* There are still some lower elts; shorten the range. */ /* There are still some lower elts; shorten the range. */
...@@ -2238,7 +2240,7 @@ find_array_ctor_elt (tree ary, tree dindex, bool insert = false) ...@@ -2238,7 +2240,7 @@ find_array_ctor_elt (tree ary, tree dindex, bool insert = false)
/* Append the element we want to insert. */ /* Append the element we want to insert. */
++middle; ++middle;
e.index = dindex; e.index = dindex;
e.value = unshare_constructor (elt.value); e.value = unshare_constructor (value);
vec_safe_insert (CONSTRUCTOR_ELTS (ary), middle, e); vec_safe_insert (CONSTRUCTOR_ELTS (ary), middle, e);
} }
else else
...@@ -2254,8 +2256,8 @@ find_array_ctor_elt (tree ary, tree dindex, bool insert = false) ...@@ -2254,8 +2256,8 @@ find_array_ctor_elt (tree ary, tree dindex, bool insert = false)
e.index = hi; e.index = hi;
else else
e.index = build2 (RANGE_EXPR, sizetype, new_lo, hi); e.index = build2 (RANGE_EXPR, sizetype, new_lo, hi);
e.value = unshare_constructor (elt.value); e.value = unshare_constructor (value);
vec_safe_insert (CONSTRUCTOR_ELTS (ary), middle+1, e); vec_safe_insert (CONSTRUCTOR_ELTS (ary), middle + 1, e);
} }
} }
return middle; return middle;
......
2018-03-13 Jakub Jelinek <jakub@redhat.com> 2018-03-13 Jakub Jelinek <jakub@redhat.com>
PR c++/84808
* g++.dg/cpp1y/constexpr-84808.C: New test.
PR c++/84704 PR c++/84704
* g++.dg/debug/pr84704.C: New test. * g++.dg/debug/pr84704.C: New test.
......
// PR c++/84808
// { dg-do compile { target c++14 } }
struct A { int i; constexpr A () : i() {} };
struct B { A a[24]; };
constexpr int
foo (int n)
{
B b;
++b.a[n + 20].i;
++b.a[n + 18].i;
++b.a[n + 16].i;
++b.a[n + 14].i;
++b.a[n + 12].i;
++b.a[n + 10].i;
++b.a[n + 8].i;
++b.a[n + 6].i;
++b.a[n + 4].i;
++b.a[n + 2].i;
++b.a[n].i;
return b.a[2].i + b.a[4].i + b.a[6].i + b.a[8].i + b.a[10].i
+ b.a[12].i + b.a[14].i + b.a[16].i + b.a[18].i + b.a[20].i + b.a[22].i;
}
constexpr int i = foo (2);
static_assert (i == 11, "");
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment