Commit e24ff973 by Richard Kenner

(layout_type...

(layout_type, case ARRAY_TYPE): Strip MAX_EXPR from upper bound when
computing length if it just protects against negative length.

From-SVN: r10430
parent 675f0e7c
...@@ -747,10 +747,28 @@ layout_type (type) ...@@ -747,10 +747,28 @@ layout_type (type)
if (index && TYPE_MAX_VALUE (index) && TYPE_MIN_VALUE (index) if (index && TYPE_MAX_VALUE (index) && TYPE_MIN_VALUE (index)
&& TYPE_SIZE (element)) && TYPE_SIZE (element))
{ {
tree length tree ub = TYPE_MAX_VALUE (index);
= size_binop (PLUS_EXPR, size_one_node, tree lb = TYPE_MIN_VALUE (index);
size_binop (MINUS_EXPR, TYPE_MAX_VALUE (index), tree length;
TYPE_MIN_VALUE (index)));
/* If UB is max (lb - 1, x), remove the MAX_EXPR since the
test for negative below covers it. */
if (TREE_CODE (ub) == MAX_EXPR
&& TREE_CODE (TREE_OPERAND (ub, 0)) == MINUS_EXPR
&& integer_onep (TREE_OPERAND (TREE_OPERAND (ub, 0), 1))
&& operand_equal_p (TREE_OPERAND (TREE_OPERAND (ub, 0), 0),
lb, 0))
ub = TREE_OPERAND (ub, 1);
else if (TREE_CODE (ub) == MAX_EXPR
&& TREE_CODE (TREE_OPERAND (ub, 1)) == MINUS_EXPR
&& integer_onep (TREE_OPERAND (TREE_OPERAND (ub, 1), 1))
&& operand_equal_p (TREE_OPERAND (TREE_OPERAND (ub, 1),
0),
lb, 0))
ub = TREE_OPERAND (ub, 0);
length = size_binop (PLUS_EXPR, size_one_node,
size_binop (MINUS_EXPR, ub, lb));
/* If neither bound is a constant and sizetype is signed, make /* If neither bound is a constant and sizetype is signed, make
sure the size is never negative. We should really do this sure the size is never negative. We should really do this
......
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