]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Gracefully handle right shifts larger than the precision.
authorAldy Hernandez <aldyh@redhat.com>
Mon, 19 Oct 2020 10:18:46 +0000 (06:18 -0400)
committerAldy Hernandez <aldyh@redhat.com>
Mon, 19 Oct 2020 12:34:01 +0000 (08:34 -0400)
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
gcc/testsuite/gcc.dg/pr97488.c [new file with mode: 0644]

index 30d2a4d3987ed5a2ff07f16608e70476ea8dce7f..21d98de2240621ed2ef2a6a534981b3b67703335 100644 (file)
@@ -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 (file)
index 0000000..96dc33c
--- /dev/null
@@ -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;
+}