From 46f4a397ab0907ce5786e1f0b92030a73e8b89ef Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Mon, 12 Oct 2020 13:00:12 -0400 Subject: [PATCH] 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. --- gcc/gimple-range-gori.cc | 5 +++-- gcc/testsuite/gcc.dg/pr97381.c | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr97381.c 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 (;;) + ; + } +} -- 2.30.2