Commit 55bf45c0 by Alan Lawrence Committed by Alan Lawrence

tree-sra.c: Fix completely_scalarize for negative indices.

	* tree-sra.c (completely_scalarize): Properly handle negative array
	indices using offset_int.

From-SVN: r229852
parent f1aa4bb3
2015-11-06 Alan Lawrence <alan.lawrence@arm.com>
* tree-sra.c (completely_scalarize): Properly handle negative array
indices using offset_int.
2015-11-06 Richard Biener <rguenther@suse.de> 2015-11-06 Richard Biener <rguenther@suse.de>
* alloc-pool.h (object_allocator::allocate): Default-initialize * alloc-pool.h (object_allocator::allocate): Default-initialize
...@@ -999,18 +999,25 @@ completely_scalarize (tree base, tree decl_type, HOST_WIDE_INT offset, tree ref) ...@@ -999,18 +999,25 @@ completely_scalarize (tree base, tree decl_type, HOST_WIDE_INT offset, tree ref)
if (maxidx) if (maxidx)
{ {
gcc_assert (TREE_CODE (maxidx) == INTEGER_CST); gcc_assert (TREE_CODE (maxidx) == INTEGER_CST);
/* MINIDX and MAXIDX are inclusive. Try to avoid overflow. */ tree domain = TYPE_DOMAIN (decl_type);
unsigned HOST_WIDE_INT lenp1 = tree_to_shwi (maxidx) /* MINIDX and MAXIDX are inclusive, and must be interpreted in
- tree_to_shwi (minidx); DOMAIN (e.g. signed int, whereas min/max may be size_int). */
unsigned HOST_WIDE_INT idx = 0; offset_int idx = wi::to_offset (minidx);
do offset_int max = wi::to_offset (maxidx);
if (!TYPE_UNSIGNED (domain))
{ {
tree nref = build4 (ARRAY_REF, elemtype, ref, size_int (idx), idx = wi::sext (idx, TYPE_PRECISION (domain));
max = wi::sext (max, TYPE_PRECISION (domain));
}
for (int el_off = offset; wi::les_p (idx, max); ++idx)
{
tree nref = build4 (ARRAY_REF, elemtype,
ref,
wide_int_to_tree (domain, idx),
NULL_TREE, NULL_TREE); NULL_TREE, NULL_TREE);
int el_off = offset + idx * el_size;
scalarize_elem (base, el_off, el_size, nref, elemtype); scalarize_elem (base, el_off, el_size, nref, elemtype);
el_off += el_size;
} }
while (++idx <= lenp1);
} }
} }
break; break;
......
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