From 2d2f4ffc97a8510e72a99ee106159aeae2627a42 Mon Sep 17 00:00:00 2001 From: Aldy Hernandez Date: Mon, 19 Oct 2020 06:18:46 -0400 Subject: [PATCH] Gracefully handle right shifts larger than the precision. gcc/ChangeLog: PR tree-optimization/97488 * range-op.cc (operator_lshift::op1_range): Handle large right shifts. gcc/testsuite/ChangeLog: * gcc.dg/pr97488.c: New test. --- gcc/range-op.cc | 4 ++++ gcc/testsuite/gcc.dg/pr97488.c | 11 +++++++++++ 2 files changed, 15 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/pr97488.c diff --git a/gcc/range-op.cc b/gcc/range-op.cc index 30d2a4d3987..21d98de2240 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -1579,6 +1579,10 @@ operator_lshift::op1_range (irange &r, wide_int shift = wi::to_wide (shift_amount); if (wi::lt_p (shift, 0, SIGNED)) return false; + if (wi::ge_p (shift, wi::uhwi (TYPE_PRECISION (type), + TYPE_PRECISION (op2.type ())), + UNSIGNED)) + return false; if (shift == 0) { r = lhs; diff --git a/gcc/testsuite/gcc.dg/pr97488.c b/gcc/testsuite/gcc.dg/pr97488.c new file mode 100644 index 00000000000..96dc33cf258 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr97488.c @@ -0,0 +1,11 @@ +// { dg-do compile } +// { dg-options "-O1 -ftree-vrp" } + +__int128 +ef (__int128 ms) +{ + int dh = 129; + int *hj = &dh; + + return ms << *hj ? ms : 0; +} -- 2.30.2