diff options
author | Andrew Pinski <pinskia@physics.uc.edu> | 2005-11-02 21:44:17 +0000 |
---|---|---|
committer | Richard Henderson <rth@gcc.gnu.org> | 2005-11-02 13:44:17 -0800 |
commit | b426200a44956b057905abb52df07e763e7e2185 (patch) | |
tree | a8a257208152510defaa462a00320fab1c588c5b /gcc/fold-const.c | |
parent | 88a33c3406ca21d94db7ca092f3f65c898e23fda (diff) | |
download | gcc-b426200a44956b057905abb52df07e763e7e2185.zip gcc-b426200a44956b057905abb52df07e763e7e2185.tar.gz gcc-b426200a44956b057905abb52df07e763e7e2185.tar.bz2 |
re PR middle-end/22429 (-1073741824 <= n && n <= 1073741823 is true where n is 1073741824)
PR 22429
* fold-const.c (build_range_check): Use unsigned when signed
overflow is undefined also. If etype is subtype, make sure that
the subtraction is in the supertype.
From-SVN: r106400
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r-- | gcc/fold-const.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 16e7eb3..6f829ad 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -4014,7 +4014,8 @@ build_range_check (tree type, tree exp, int in_p, tree low, tree high) } value = const_binop (MINUS_EXPR, high, low, 0); - if (value != 0 && TREE_OVERFLOW (value) && ! TYPE_UNSIGNED (etype)) + if (value != 0 && (!flag_wrapv || TREE_OVERFLOW (value)) + && ! TYPE_UNSIGNED (etype)) { tree utype, minv, maxv; @@ -4025,6 +4026,11 @@ build_range_check (tree type, tree exp, int in_p, tree low, tree high) case INTEGER_TYPE: case ENUMERAL_TYPE: case CHAR_TYPE: + /* 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 (TREE_TYPE (etype)) + etype = TREE_TYPE (etype); utype = lang_hooks.types.unsigned_type (etype); maxv = fold_convert (utype, TYPE_MAX_VALUE (etype)); maxv = range_binop (PLUS_EXPR, NULL_TREE, maxv, 1, |