Don't assert on a negative shift.
authorAndrew MacLeod <amacleod@redhat.com>
Fri, 16 Oct 2020 19:02:42 +0000 (15:02 -0400)
committerAndrew MacLeod <amacleod@redhat.com>
Fri, 16 Oct 2020 19:05:11 +0000 (15:05 -0400)
Don't assert, simply Return false for negative shifts as we can't tell
anything about the operand.

PR tree-optimization/97462
gcc/
* range-op.cc (operator_lshift::op1_range): Don't trap on negative
shifts.
gcc/testsuite/
* gcc.dg/pr97462.c: New file.

gcc/range-op.cc
gcc/testsuite/gcc.dg/pr97462.c [new file with mode: 0644]

index 6108de367ad5837d9ff21101431e2f51ab46b093..de4cfe45a48d8d8ba85b99f2d8123f36c685e608 100644 (file)
@@ -1577,7 +1577,8 @@ operator_lshift::op1_range (irange &r,
   if (op2.singleton_p (&shift_amount))
     {
       wide_int shift = wi::to_wide (shift_amount);
-      gcc_checking_assert (wi::gt_p (shift, 0, SIGNED));
+      if (wi::lt_p (shift, 0, SIGNED))
+       return false;
 
       // Work completely in unsigned mode to start.
       tree utype = type;
diff --git a/gcc/testsuite/gcc.dg/pr97462.c b/gcc/testsuite/gcc.dg/pr97462.c
new file mode 100644 (file)
index 0000000..52c0533
--- /dev/null
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -w" } */
+
+int a, b;
+
+void d ()
+{
+  a << ~0 && b;
+  b = a;
+}