]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gimple: Don't assert that switch has nondefault cases during lowering [PR120080]
authorFilip Kastl <fkastl@suse.cz>
Sat, 10 May 2025 14:18:33 +0000 (16:18 +0200)
committerFilip Kastl <fkastl@suse.cz>
Sat, 10 May 2025 14:18:33 +0000 (16:18 +0200)
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 <fkastl@suse.cz>
gcc/testsuite/gcc.dg/tree-ssa/pr120080.c [new file with mode: 0644]
gcc/tree-switch-conversion.cc

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr120080.c b/gcc/testsuite/gcc.dg/tree-ssa/pr120080.c
new file mode 100644 (file)
index 0000000..d71ef5e
--- /dev/null
@@ -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;
+
+}
index dea217a01efb2342a69c7d2e987fe5440d1ca963..bd4de966892cd58019e1ce8d60f1759901c91e3b 100644 (file)
@@ -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