public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PUSHED] PR tree-optimization/96967 - cast label range to type of switch operand
@ 2020-09-08 11:45 Aldy Hernandez
  0 siblings, 0 replies; only message in thread
From: Aldy Hernandez @ 2020-09-08 11:45 UTC (permalink / raw)
  To: gcc-patches

This is the same issue as PR96818.  It's another intersect that's 
missing a cast in the same function.  I missed it in the previous PR.

Pushed as obvious.

	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 | 36 
+++++++++++++++++++++++++++++++++
  gcc/tree-vrp.c                          |  2 ++
  2 files changed, 38 insertions(+)
  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr96967.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
index 0000000..249dfc7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr96967.c
@@ -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;
+}
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index f7b0692..b493e40 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -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;
-- 
1.8.3.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-09-08 11:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-08 11:45 [PUSHED] PR tree-optimization/96967 - cast label range to type of switch operand Aldy Hernandez

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).