In various situations a cast that is ultimately unreahcable may produce
an UNDEFINED result, and we can't check the bounds in this case.
PR tree-optimization/120277
gcc/
* range-op-ptr.cc (operator_cast::fold_range): Check if the cast
if UNDEFINED before setting bounds.
gcc/testsuite/
* gcc.dg/pr120277.c: New.
int_range<2> tmp = inner;
tree pointer_uint_type = make_unsigned_type (TYPE_PRECISION (type));
range_cast (tmp, pointer_uint_type);
- r.set (type, tmp.lower_bound (), tmp.upper_bound ());
- r.update_bitmask (tmp.get_bitmask ());
+ // Casts may cause ranges to become UNDEFINED based on bitmasks.
+ if (tmp.undefined_p ())
+ r.set_varying (type);
+ else
+ {
+ r.set (type, tmp.lower_bound (), tmp.upper_bound ());
+ r.update_bitmask (tmp.get_bitmask ());
+ }
return true;
}
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+int a, b;
+int c(int d, long e) {
+ switch (d) {
+ case 129:
+ a = 1;
+ case 128:
+ break;
+ default:
+ return 1;
+ }
+ *(int *)e = 0;
+}
+void f(int d, long e) { c(d, e); }
+void g() {
+ int h = b * sizeof(int);
+ f(h + 7, h);
+}
+void main() {}