From: Andrew MacLeod Date: Mon, 19 Jan 2026 18:44:25 +0000 (-0500) Subject: Do not trap on a stmt with no basic block. X-Git-Tag: basepoints/gcc-17~1867 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4ac080e384cd30d37fac069d791b813100e6524a;p=thirdparty%2Fgcc.git Do not trap on a stmt with no basic block. 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. --- diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc index f64c53a7371..4c768ed3a07 100644 --- a/gcc/gimple-range.cc +++ b/gcc/gimple-range.cc @@ -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 (stmt)) diff --git a/gcc/testsuite/gcc.dg/pr123314.c b/gcc/testsuite/gcc.dg/pr123314.c new file mode 100644 index 00000000000..785992b4ff3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr123314.c @@ -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; + } +}