Handle right shifts by zero in range-ops.
authorAldy Hernandez <aldyh@redhat.com>
Mon, 19 Oct 2020 07:48:27 +0000 (09:48 +0200)
committerAldy Hernandez <aldyh@redhat.com>
Mon, 19 Oct 2020 09:37:15 +0000 (11:37 +0200)
If the shift amount in operator_lshift::op1_range was zero, an invalid range
of [1, 0] was being created.

gcc/ChangeLog:

PR tree-optimization/97467
* range-op.cc (operator_lshift::op1_range): Handle shifts by 0.

gcc/testsuite/ChangeLog:

* gcc.dg/pr97467.c: New test.

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

index 0efa00186e829a3ea93ae732be84162b3bb6da81..30d2a4d3987ed5a2ff07f16608e70476ea8dce7f 100644 (file)
@@ -1579,6 +1579,11 @@ operator_lshift::op1_range (irange &r,
       wide_int shift = wi::to_wide (shift_amount);
       if (wi::lt_p (shift, 0, SIGNED))
        return false;
+      if (shift == 0)
+       {
+         r = lhs;
+         return true;
+       }
 
       // Work completely in unsigned mode to start.
       tree utype = type;
diff --git a/gcc/testsuite/gcc.dg/pr97467.c b/gcc/testsuite/gcc.dg/pr97467.c
new file mode 100644 (file)
index 0000000..dcbd218
--- /dev/null
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-Os" } */
+
+int a;
+long b;
+unsigned int c = 1;
+
+int main () {
+  int e;
+  for (; c <= 0; c++) {
+    int f = 0;
+    b = e;
+    a = f || b << c;
+  }
+  return 0;
+}