From: Aldy Hernandez Date: Mon, 12 Oct 2020 08:08:28 +0000 (-0400) Subject: Ignore shifts larger than precision in operator_rshift::op1_range. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e1b4fbfea6ad24f47279b90aec27ef1512625c80;p=gcc.git Ignore shifts larger than precision in operator_rshift::op1_range. gcc/ChangeLog: PR tree-optimization/97371 * range-op.cc (operator_rshift::op1_range): Ignore shifts larger than or equal to type precision. gcc/testsuite/ChangeLog: * gcc.dg/pr97371.c: New test. --- diff --git a/gcc/range-op.cc b/gcc/range-op.cc index d1a11b34894..ce6ae2de20c 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -1626,6 +1626,13 @@ operator_rshift::op1_range (irange &r, tree shift; if (op2.singleton_p (&shift)) { + // Ignore nonsensical shifts. + unsigned prec = TYPE_PRECISION (type); + if (wi::ge_p (wi::to_wide (shift), + wi::uhwi (prec, TYPE_PRECISION (TREE_TYPE (shift))), + UNSIGNED)) + return false; + // Folding the original operation may discard some impossible // ranges from the LHS. int_range_max lhs_refined; diff --git a/gcc/testsuite/gcc.dg/pr97371.c b/gcc/testsuite/gcc.dg/pr97371.c new file mode 100644 index 00000000000..ffefad0287e --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr97371.c @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -w" } */ + +int a, b; +void c() { + if (b >> 38) + a = b; +}