https://gcc.gnu.org/g:3df53e5554c86bfbf7f7dbfd3052678eb03afcdb
commit r14-10770-g3df53e5554c86bfbf7f7dbfd3052678eb03afcdb Author: Jakub Jelinek <ja...@redhat.com> Date: Tue Oct 1 09:49:49 2024 +0200 range-cache: Fix ICE on SSA_NAME with def_stmt not yet in the IL [PR116898] Some passes like the bitint lowering queue some statements on edges and only commit them at the end of the pass. If they use ranger at the same time, the ranger might see such SSA_NAMEs and ICE on those. The following patch instead just punts on them. 2024-10-01 Jakub Jelinek <ja...@redhat.com> PR middle-end/116898 * gimple-range-cache.cc (ranger_cache::block_range): If a SSA_NAME with NULL def_bb isn't SSA_NAME_IS_DEFAULT_DEF, return false instead of failing assertion. Formatting fix. * gcc.dg/bitint-110.c: New test. (cherry picked from commit bdbd0607d5933cdecbf7e009a42f1d9486dddf44) Diff: --- gcc/gimple-range-cache.cc | 9 ++++++--- gcc/testsuite/gcc.dg/bitint-110.c | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc index a33b7a738723..0a5754139308 100644 --- a/gcc/gimple-range-cache.cc +++ b/gcc/gimple-range-cache.cc @@ -1239,13 +1239,16 @@ ranger_cache::block_range (vrange &r, basic_block bb, tree name, bool calc) gimple *def_stmt = SSA_NAME_DEF_STMT (name); basic_block def_bb = NULL; if (def_stmt) - def_bb = gimple_bb (def_stmt);; + def_bb = gimple_bb (def_stmt); if (!def_bb) { // If we get to the entry block, this better be a default def // or range_on_entry was called for a block not dominated by - // the def. - gcc_checking_assert (SSA_NAME_IS_DEFAULT_DEF (name)); + // the def. But it could be also SSA_NAME defined by a statement + // not yet in the IL (such as queued edge insertion), in that case + // just punt. + if (!SSA_NAME_IS_DEFAULT_DEF (name)) + return false; def_bb = ENTRY_BLOCK_PTR_FOR_FN (cfun); } diff --git a/gcc/testsuite/gcc.dg/bitint-110.c b/gcc/testsuite/gcc.dg/bitint-110.c new file mode 100644 index 000000000000..4ba2f93856e5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/bitint-110.c @@ -0,0 +1,20 @@ +/* PR middle-end/116898 */ +/* { dg-do compile { target bitint575 } } */ +/* { dg-options "-O -finstrument-functions -fnon-call-exceptions" } */ + +_BitInt(127) a; +_BitInt(511) b; + +void +foo (_BitInt(31) c) +{ + do + { + c %= b; +again: + } + while (c); + a /= 0; /* { dg-warning "division by zero" } */ + c -= a; + goto again; +}