diff options
author | Aldy Hernandez <aldyh@redhat.com> | 2020-10-19 06:18:46 -0400 |
---|---|---|
committer | Aldy Hernandez <aldyh@redhat.com> | 2020-10-19 08:34:01 -0400 |
commit | 2d2f4ffc97a8510e72a99ee106159aeae2627a42 (patch) | |
tree | 0efeb2ede672aeaa79841811a21a8439a2882fe2 | |
parent | 11b8cca0831ee37cc534ff27cd8d32ac5aace6f7 (diff) | |
download | gcc-2d2f4ffc97a8510e72a99ee106159aeae2627a42.zip gcc-2d2f4ffc97a8510e72a99ee106159aeae2627a42.tar.gz gcc-2d2f4ffc97a8510e72a99ee106159aeae2627a42.tar.bz2 |
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.
-rw-r--r-- | gcc/range-op.cc | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr97488.c | 11 |
2 files changed, 15 insertions, 0 deletions
diff --git a/gcc/range-op.cc b/gcc/range-op.cc index 30d2a4d..21d98de 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 0000000..96dc33c --- /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; +} |