aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPer Bothner <bothner@gcc.gnu.org>1993-09-12 23:01:37 -0700
committerPer Bothner <bothner@gcc.gnu.org>1993-09-12 23:01:37 -0700
commitd4c89139666d87afd6544277c7e363716e3d7d9e (patch)
tree3228495a06f49761a4990498649e3983a717d15f /gcc
parent59b22f6465f0e7bee50b3dc18e97c111a5aa521e (diff)
downloadgcc-d4c89139666d87afd6544277c7e363716e3d7d9e.zip
gcc-d4c89139666d87afd6544277c7e363716e3d7d9e.tar.gz
gcc-d4c89139666d87afd6544277c7e363716e3d7d9e.tar.bz2
(expand_expr, ARRAY_REF): Coerce low_bound to sizetype.
From-SVN: r5313
Diffstat (limited to 'gcc')
-rw-r--r--gcc/expr.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/gcc/expr.c b/gcc/expr.c
index b640ebc..85b2555 100644
--- a/gcc/expr.c
+++ b/gcc/expr.c
@@ -3889,9 +3889,20 @@ expand_expr (exp, target, tmode, modifier)
tree index_type = TREE_TYPE (index);
int i;
- /* Optimize the special-case of a zero lower bound. */
+ /* Optimize the special-case of a zero lower bound.
+
+ We convert the low_bound to sizetype to avoid some problems
+ with constant folding. (E.g. suppose the lower bound is 1,
+ and its mode is QI. Without the conversion, (ARRAY
+ +(INDEX-(unsigned char)1)) becomes ((ARRAY+(-(unsigned char)1))
+ +INDEX), which becomes (ARRAY+255+INDEX). Oops!)
+
+ But sizetype isn't quite right either (especially if
+ the lowbound is negative). FIXME */
+
if (! integer_zerop (low_bound))
- index = fold (build (MINUS_EXPR, index_type, index, low_bound));
+ index = fold (build (MINUS_EXPR, index_type, index,
+ convert (sizetype, low_bound)));
if (TREE_CODE (index) != INTEGER_CST
|| TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)