1 The problem here is fold (build_range_check) converts
2 "-1073741824 <= n && n <= 1073741823" to "n + 1073741824 >= 0"
3 which makes depends on signed overflow being defined. Fold later converts
4 it to "n >= -1073741824" by my recent patch which is wrong.
5 This patch fixes the problem by using unsigned types if signed overflow
8 OK? Bootstrapped and tested on x86_64-pc-linux-gnu with no regressions.
13 * fold-const.c (build_range_check): Use unsigned when signed
14 overflow is undefined also. If etype is subtype, make sure that
15 the subtraction is in the supper type.
17 --- a/gcc/fold-const.c 2005-10-19 08:15:39.000000000 +0000
18 +++ b/gcc/fold-const.c 2005-10-19 08:29:46.574021728 +0000
22 value = const_binop (MINUS_EXPR, high, low, 0);
23 - if (value != 0 && TREE_OVERFLOW (value) && ! TYPE_UNSIGNED (etype))
24 + if (value != 0 && (!flag_wrapv || TREE_OVERFLOW (value))
25 + && ! TYPE_UNSIGNED (etype))
27 tree utype, minv, maxv;
29 @@ -4016,6 +4017,11 @@
33 + /* There is no requirement that LOW be within the range of ETYPE
34 + if the latter is a subtype. It must, however, be within the base
35 + type of ETYPE. So be sure we do the subtraction in that type. */
36 + if (TREE_TYPE (etype))
37 + etype = TREE_TYPE (etype);
38 utype = lang_hooks.types.unsigned_type (etype);
39 maxv = fold_convert (utype, TYPE_MAX_VALUE (etype));
40 maxv = range_binop (PLUS_EXPR, NULL_TREE, maxv, 1,