From: Aldy Hernandez Date: Tue, 8 Sep 2020 07:42:03 +0000 (+0000) Subject: PR tree-optimization/96967 - cast label range to type of switch operand X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=19b0fed7c2d3663f0f144ca8557b6af29bafa4e3;p=gcc.git PR tree-optimization/96967 - cast label range to type of switch operand PR tree-optimization/96967 * tree-vrp.c (find_case_label_range): Cast label range to type of switch operand. --- 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 00000000000..249dfc7fa11 --- /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 f7b0692a407..b493e402382 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;