public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-2951] PR tree-optimization/96818 - cast label range to type of switch operand
@ 2020-08-31 14:55 Aldy Hernandez
0 siblings, 0 replies; only message in thread
From: Aldy Hernandez @ 2020-08-31 14:55 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:d503cd98713a41aad34ade2b9b0d9973efb21e11
commit r11-2951-gd503cd98713a41aad34ade2b9b0d9973efb21e11
Author: Aldy Hernandez <aldyh@redhat.com>
Date: Fri Aug 28 18:44:58 2020 +0200
PR tree-optimization/96818 - cast label range to type of switch operand
PR tree-optimization/96818
* tree-vrp.c (find_case_label_range): Cast label range to
type of switch operand.
Diff:
---
gcc/testsuite/g++.dg/pr96818.C | 28 ++++++++++++++++++++++++++++
gcc/testsuite/gcc.dg/pr96818.c | 14 ++++++++++++++
gcc/tree-vrp.c | 2 ++
3 files changed, 44 insertions(+)
diff --git a/gcc/testsuite/g++.dg/pr96818.C b/gcc/testsuite/g++.dg/pr96818.C
new file mode 100644
index 00000000000..134bf8b6980
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr96818.C
@@ -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
index 00000000000..ea2ac540d39
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr96818.c
@@ -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;
+}
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index 8c1a1854daa..a165164bb40 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -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);
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-08-31 14:55 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-31 14:55 [gcc r11-2951] PR tree-optimization/96818 - 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).