PR tree-optimization/96967 - cast label range to type of switch operand
authorAldy Hernandez <aldyh@redhat.com>
Tue, 8 Sep 2020 07:42:03 +0000 (07:42 +0000)
committerAldy Hernandez <aldyh@redhat.com>
Tue, 8 Sep 2020 11:43:35 +0000 (13:43 +0200)
PR tree-optimization/96967
* tree-vrp.c (find_case_label_range): Cast label range to
type of switch operand.

gcc/testsuite/gcc.dg/tree-ssa/pr96967.c [new file with mode: 0644]
gcc/tree-vrp.c

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr96967.c b/gcc/testsuite/gcc.dg/tree-ssa/pr96967.c
new file mode 100644 (file)
index 0000000..249dfc7
--- /dev/null
@@ -0,0 +1,36 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fshort-enums" } */
+
+enum re {
+  o3,
+};
+
+int
+uj (int mq, enum re dn)
+{
+  enum re nr = mq;
+
+  switch (nr)
+    {
+    case 4:
+      if (dn == 0)
+        goto wdev_inactive_unlock;
+      break;
+
+    default:
+      break;
+    }
+
+  switch (nr)
+    {
+    case 0:
+    case 4:
+      return 0;
+
+    default:
+      break;
+    }
+
+ wdev_inactive_unlock:
+  return 1;
+}
index f7b0692a407674a46a8c4844c57bda86c287dde2..b493e4023821cc5e85fe57015ed1535a810d5f48 100644 (file)
@@ -3828,6 +3828,8 @@ find_case_label_range (gswitch *switch_stmt, const irange *range_of_op)
       tree case_high
        = CASE_HIGH (label) ? CASE_HIGH (label) : CASE_LOW (label);
       int_range_max label_range (CASE_LOW (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 == *range_of_op)
        return label;