We were ignoring the return value if op2 returned false and getting garbage ranges propagated.
gcc/ChangeLog:
PR tree-optimization/97381
* gimple-range-gori.cc (gori_compute::compute_operand2_range): If a range cannot be
calculated through operand 2, return false.
gcc/testsuite/ChangeLog:
* gcc.dg/pr97381.c: New test.
expr_range_in_bb (op2_range, op2, gimple_bb (stmt));
// Intersect with range for op2 based on lhs and op1.
- if (gimple_range_calc_op2 (r, stmt, lhs, op1_range))
- op2_range.intersect (r);
+ if (!gimple_range_calc_op2 (r, stmt, lhs, op1_range))
+ return false;
+ op2_range.intersect (r);
gimple *src_stmt = SSA_NAME_DEF_STMT (op2);
// If def stmt is outside of this BB, then name must be an import.
--- /dev/null
+// { dg-do compile }
+// { dg-options "-O2" }
+
+int a;
+void b() {
+ char c = 27;
+ for (; c <= 85; c += 1) {
+ a /= 148372120 * c;
+ if (a)
+ for (;;)
+ ;
+ }
+}