aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRichard Kenner <kenner@gcc.gnu.org>1995-10-03 19:15:52 -0400
committerRichard Kenner <kenner@gcc.gnu.org>1995-10-03 19:15:52 -0400
commite24ff9733326709acd0add575db7e9962abf7554 (patch)
treedbbf3893c7fcbb0adff6ee1dd5bc91f2f21540b9 /gcc
parent675f0e7cb2931a7f0d08f422b1a6564fb3b28b6b (diff)
downloadgcc-e24ff9733326709acd0add575db7e9962abf7554.zip
gcc-e24ff9733326709acd0add575db7e9962abf7554.tar.gz
gcc-e24ff9733326709acd0add575db7e9962abf7554.tar.bz2
(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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/stor-layout.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c
index 3156c58..8cdbf86 100644
--- a/gcc/stor-layout.c
+++ b/gcc/stor-layout.c
@@ -747,10 +747,28 @@ layout_type (type)
if (index && TYPE_MAX_VALUE (index) && TYPE_MIN_VALUE (index)
&& TYPE_SIZE (element))
{
- tree length
- = size_binop (PLUS_EXPR, size_one_node,
- size_binop (MINUS_EXPR, TYPE_MAX_VALUE (index),
- TYPE_MIN_VALUE (index)));
+ tree ub = TYPE_MAX_VALUE (index);
+ tree lb = TYPE_MIN_VALUE (index);
+ tree length;
+
+ /* 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
sure the size is never negative. We should really do this