diff options
author | kenner <kenner@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-11-18 13:07:06 +0000 |
---|---|---|
committer | kenner <kenner@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-11-18 13:07:06 +0000 |
commit | 3f7c18bc03b880e58212631e4ac9bca06c7b2980 (patch) | |
tree | 26844d91ee0e0cb507b8e1d46555bb252b31b8d7 /gcc/fold-const.c | |
parent | 657236c3e6d27661284d415ae0baa50aaef1ee6c (diff) | |
download | gcc-3f7c18bc03b880e58212631e4ac9bca06c7b2980.tar.gz |
* fold-const.c (build_range_check): Use proper type for subtraction
when merging lower bound.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@107178 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r-- | gcc/fold-const.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 343cfae6903..abaac755e3b 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -4062,10 +4062,22 @@ build_range_check (tree type, tree exp, int in_p, tree low, tree high) } if (value != 0 && ! TREE_OVERFLOW (value)) - return build_range_check (type, - fold_build2 (MINUS_EXPR, etype, exp, low), - 1, fold_convert (etype, integer_zero_node), - value); + { + /* There is no requirement that LOW be within the range of ETYPE + if the latter is a subtype. It must, however, be within the base + type of ETYPE. So be sure we do the subtraction in that type. */ + if (INTEGRAL_TYPE_P (etype) && TREE_TYPE (etype)) + { + etype = TREE_TYPE (etype); + exp = fold_convert (etype, exp); + low = fold_convert (etype, low); + value = fold_convert (etype, value); + } + + return build_range_check (type, + fold_build2 (MINUS_EXPR, etype, exp, low), + 1, build_int_cst (etype, 0), value); + } return 0; } |