From: Aldy Hernandez Date: Mon, 19 Oct 2020 10:18:46 +0000 (-0400) Subject: Gracefully handle right shifts larger than the precision. X-Git-Tag: basepoints/gcc-12~4187 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2d2f4ffc97a8510e72a99ee106159aeae2627a42;p=thirdparty%2Fgcc.git 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. --- diff --git a/gcc/range-op.cc b/gcc/range-op.cc index 30d2a4d3987e..21d98de22406 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 000000000000..96dc33cf2589 --- /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; +}