]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Do not trap on a stmt with no basic block.
authorAndrew MacLeod <amacleod@redhat.com>
Mon, 19 Jan 2026 18:44:25 +0000 (13:44 -0500)
committerAndrew MacLeod <amacleod@redhat.com>
Tue, 20 Jan 2026 19:22:54 +0000 (14:22 -0500)
WHen calculating ranges for statements not in the IL, avoid looking for
range on entry values.

PR tree-optimization/123314
gcc/
* gimple-range.cc (gimple_ranger::range_on_entry): Do not check
ranger cache for an SSA_NAME with no BB.
(gimple_ranger::prefill_stmt_dependencies): Stop filling
dependencies when an out-of IL name is encountered.

gcc/testsuite/
* gcc.dg/pr123314.c: New.

gcc/gimple-range.cc
gcc/testsuite/gcc.dg/pr123314.c [new file with mode: 0644]

index f64c53a7371d67fff0ad0308bfb265c024c49b98..4c768ed3a07d2a885b74886fb8999414e81d088a 100644 (file)
@@ -171,7 +171,7 @@ gimple_ranger::range_on_entry (vrange &r, basic_block bb, tree name)
   range_of_stmt (r, SSA_NAME_DEF_STMT (name), name);
 
   // Now see if there is any on_entry value which may refine it.
-  if (m_cache.block_range (entry_range, bb, name))
+  if (bb && m_cache.block_range (entry_range, bb, name))
     r.intersect (entry_range);
 
   if (idx)
@@ -389,7 +389,9 @@ gimple_ranger::prefill_stmt_dependencies (tree ssa)
 
   unsigned idx;
   gimple *stmt = SSA_NAME_DEF_STMT (ssa);
-  gcc_checking_assert (stmt && gimple_bb (stmt));
+  gcc_checking_assert (stmt);
+  if (!gimple_bb (stmt))
+    return;
 
   // Only pre-process range-ops and phis.
   if (!gimple_range_op_handler::supported_p (stmt) && !is_a<gphi *> (stmt))
diff --git a/gcc/testsuite/gcc.dg/pr123314.c b/gcc/testsuite/gcc.dg/pr123314.c
new file mode 100644 (file)
index 0000000..785992b
--- /dev/null
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-O3" } */
+/* { dg-additional-options "-march=armv9-a" { target aarch64*-*-* } } */
+/* { dg-additional-options "-march=skylake-avx512" { target x86_64*-*-* } } */
+
+extern char a[];
+extern short b[], c[];
+extern int h[];
+void i() {
+  for (char d;;)
+    for (int e = 0; e < 9; e++) {
+      for (int f; f < 9; f += 4)
+        c[d] = 0;
+      for (int g = 0; g < 9; g += 3)
+        h[1 + d] = (a[d] ? a[3] : 7 ? b[7] : 0) / 6;
+    }
+}