PR tree-optimization/96818 - cast label range to type of switch operand
authorAldy Hernandez <aldyh@redhat.com>
Fri, 28 Aug 2020 16:44:58 +0000 (18:44 +0200)
committerAldy Hernandez <aldyh@redhat.com>
Mon, 31 Aug 2020 14:55:16 +0000 (16:55 +0200)
PR tree-optimization/96818
* tree-vrp.c (find_case_label_range): Cast label range to
type of switch operand.

gcc/testsuite/g++.dg/pr96818.C [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr96818.c [new file with mode: 0644]
gcc/tree-vrp.c

diff --git a/gcc/testsuite/g++.dg/pr96818.C b/gcc/testsuite/g++.dg/pr96818.C
new file mode 100644 (file)
index 0000000..134bf8b
--- /dev/null
@@ -0,0 +1,28 @@
+// { dg-do compile }
+// { dg-options "-O2" }
+
+bool operatorY ();
+
+struct l
+{
+  int m;
+  int k;
+  void n ();
+    l ()
+  {
+    while (operatorY ())
+      switch ((unsigned char) k)
+       case 0:
+       {
+         n ();
+         case 1:if (m)
+           ;
+       }
+  }
+};
+
+void
+p ()
+{
+  l ();
+}
diff --git a/gcc/testsuite/gcc.dg/pr96818.c b/gcc/testsuite/gcc.dg/pr96818.c
new file mode 100644 (file)
index 0000000..ea2ac54
--- /dev/null
@@ -0,0 +1,14 @@
+// { dg-do compile }
+// { dg-options "-O2" }
+
+int a, b, c;
+void d() {
+  unsigned short e;
+  while (b)
+    ;
+  e = (e + 5) / a;
+  switch (e)
+  case 0:
+  case 3:
+    c = a;
+}
index 8c1a1854daafe722785b0b05f8e02bd2bbf205ec..a165164bb40db03151ae2e3e86cd1c06109f8046 100644 (file)
@@ -3850,6 +3850,8 @@ find_case_label_range (gswitch *switch_stmt, const irange *range_of_op)
       if (!case_high)
        case_high = CASE_LOW (max_label);
       widest_irange label_range (CASE_LOW (min_label), case_high);
+      if (!types_compatible_p (label_range.type (), range_of_op->type ()))
+       range_cast (label_range, range_of_op->type ());
       label_range.intersect (range_of_op);
       if (label_range.undefined_p ())
        return gimple_switch_label (switch_stmt, 0);