diff --git a/gcc/gimple-range-edge.cc b/gcc/gimple-range-edge.cc index e3a197a2293..d2387289ad2 100644 --- a/gcc/gimple-range-edge.cc +++ b/gcc/gimple-range-edge.cc @@ -159,8 +159,14 @@ gimple_outgoing_range::calc_switch_ranges (gswitch *sw) // Remove the case range from the default case. int_range_max def_range (type, low, high); range_cast (def_range, type); - def_range.invert (); - default_range.intersect (def_range); + // If all possible values are taken, set default_range to UNDEFINED. + if (def_range.varying_p ()) + default_range.set_undefined (); + else + { + def_range.invert (); + default_range.intersect (def_range); + } // Create/union this case with anything on else on the edge. int_range_max case_range (type, low, high); diff --git a/gcc/testsuite/gcc.dg/pr117398.c b/gcc/testsuite/gcc.dg/pr117398.c new file mode 100644 index 00000000000..c43f2a3ed6b --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr117398.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +int a; +void c(void); +int d(_Bool b) { + switch (b+0) { + case 0: + break; + case 1: + break; + default: + c(); + } + if (b) + return a; +}