From: Andrew MacLeod Date: Mon, 12 Oct 2020 17:00:12 +0000 (-0400) Subject: Do not ignore failures from gimple_range_calc_op2. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=46f4a397ab0907ce5786e1f0b92030a73e8b89ef;p=gcc.git Do not ignore failures from gimple_range_calc_op2. 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. --- diff --git a/gcc/gimple-range-gori.cc b/gcc/gimple-range-gori.cc index 986427669a7..c4bfc658319 100644 --- a/gcc/gimple-range-gori.cc +++ b/gcc/gimple-range-gori.cc @@ -920,8 +920,9 @@ gori_compute::compute_operand2_range (irange &r, gimple *stmt, 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. diff --git a/gcc/testsuite/gcc.dg/pr97381.c b/gcc/testsuite/gcc.dg/pr97381.c new file mode 100644 index 00000000000..947692cb1f6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr97381.c @@ -0,0 +1,13 @@ +// { dg-do compile } +// { dg-options "-O2" } + +int a; +void b() { + char c = 27; + for (; c <= 85; c += 1) { + a /= 148372120 * c; + if (a) + for (;;) + ; + } +}