diff mbox series

[committed] range-cache: Fix ICE on SSA_NAME with def_stmt not yet in the IL [PR116898]

Message ID Zvuv/Rt0KNqC7QxC@tucnak
State New
Headers show
Series [committed] range-cache: Fix ICE on SSA_NAME with def_stmt not yet in the IL [PR116898] | expand

Commit Message

Jakub Jelinek Oct. 1, 2024, 8:17 a.m. UTC
Hi!

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.

Bootstrapped/regtested on x86_64-linux and i686-linux, preapproved by Andrew
in the PR, committed to trunk.

2024-10-01  Jakub Jelinek  <jakub@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.


	Jakub
diff mbox series

Patch

--- gcc/gimple-range-cache.cc.jj	2024-08-12 10:49:12.687608080 +0200
+++ gcc/gimple-range-cache.cc	2024-09-30 18:50:52.314056272 +0200
@@ -1284,13 +1284,16 @@  ranger_cache::block_range (vrange &r, ba
       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);
 	}
 
--- gcc/testsuite/gcc.dg/bitint-110.c.jj	2024-09-30 18:52:50.098424063 +0200
+++ gcc/testsuite/gcc.dg/bitint-110.c	2024-09-30 18:54:38.183925375 +0200
@@ -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;
+}