https://gcc.gnu.org/g:358a5aedf2b5b61f4edfc7964144355a4897dbb9

commit r16-513-g358a5aedf2b5b61f4edfc7964144355a4897dbb9
Author: Filip Kastl <fka...@suse.cz>
Date:   Sat May 10 16:18:33 2025 +0200

    gimple: Don't assert that switch has nondefault cases during lowering 
[PR120080]
    
    I have mistakenly assumed that switch lowering cannot encounter a switch
    with zero clusters.  This patch removes the relevant assert and instead
    gives up bit-test lowering when this happens.
    
            PR tree-optimization/120080
    
    gcc/ChangeLog:
    
            * tree-switch-conversion.cc (bit_test_cluster::find_bit_tests):
            Replace assert with return.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.dg/tree-ssa/pr120080.c: New test.
    
    Signed-off-by: Filip Kastl <fka...@suse.cz>

Diff:
---
 gcc/testsuite/gcc.dg/tree-ssa/pr120080.c | 26 ++++++++++++++++++++++++++
 gcc/tree-switch-conversion.cc            |  8 +++++---
 2 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr120080.c 
b/gcc/testsuite/gcc.dg/tree-ssa/pr120080.c
new file mode 100644
index 000000000000..d71ef5e9dd05
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr120080.c
@@ -0,0 +1,26 @@
+/* { dg-do compile } */
+/* { dg-options "-fgimple -O2" } */
+
+void __GIMPLE (ssa,startwith("switchlower1"))
+foo (int b)
+{
+  __BB(2):
+  switch (b) {default: L9; case 0: L5; case 5: L5; case 101: L5; }
+
+  __BB(3):
+L9:
+  switch (b) {default: L7; case 5: L6; case 101: L6; }
+
+  __BB(4):
+L6:
+  __builtin_unreachable ();
+
+  __BB(5):
+L7:
+  __builtin_trap ();
+
+  __BB(6):
+L5:
+  return;
+
+}
diff --git a/gcc/tree-switch-conversion.cc b/gcc/tree-switch-conversion.cc
index dea217a01efb..bd4de966892c 100644
--- a/gcc/tree-switch-conversion.cc
+++ b/gcc/tree-switch-conversion.cc
@@ -1793,12 +1793,14 @@ bit_test_cluster::find_bit_tests (vec<cluster *> 
&clusters, int max_c)
      end up with as few clusters as possible.  */
 
   unsigned l = clusters.length ();
-  auto_vec<min_cluster_item> min;
-  min.reserve (l + 1);
 
-  gcc_checking_assert (l > 0);
+  if (l == 0)
+    return clusters.copy ();
   gcc_checking_assert (l <= INT_MAX);
 
+  auto_vec<min_cluster_item> min;
+  min.reserve (l + 1);
+
   int bits_in_word = GET_MODE_BITSIZE (word_mode);
 
   /* First phase: Compute the minimum number of clusters for each prefix of the

Reply via email to