+2005-11-02 Andrew Pinski <pinskia@physics.uc.edu>
+
+ 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.
+
2005-11-02 Richard Henderson <rth@redhat.com>
PR target/24178
}
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;
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,
--- /dev/null
+extern void abort (void);
+
+#define N (1 << (sizeof(int) * __CHAR_BIT__ - 2))
+
+int f(int n)
+{
+ if (-N <= n && n <= N-1)
+ return 1;
+ return 0;
+}
+
+int main ()
+{
+ if (f (N))
+ abort ();
+ return 0;
+}