middle-end/112785 - guard against last_clique overflow

Message ID 20231204143342.1EBC4139E2@imap2.dmz-prg2.suse.org
State Committed
Commit 0c2ea80a4ffbddc0bc29f5badaf2ae43e59483b2
Headers
Series middle-end/112785 - guard against last_clique overflow |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm warning Patch is already merged
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 warning Patch is already merged

Commit Message

Richard Biener Dec. 4, 2023, 2:33 p.m. UTC
  The PR shows that we'll ICE eventually when last_clique wraps.  The
following avoids this by refusing to hand out new cliques after
exhausting them.  We then use zero (no clique) as conservative
fallback.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

	PR middle-end/112785
	* function.h (get_new_clique): New inline function handling
	last_clique overflow.
	* cfgrtl.cc (duplicate_insn_chain): Use it.
	* tree-cfg.cc (gimple_duplicate_bb): Likewise.
	* tree-inline.cc (remap_dependence_clique): Likewise.
---
 gcc/cfgrtl.cc      |  2 +-
 gcc/function.h     | 11 +++++++++++
 gcc/tree-cfg.cc    |  2 +-
 gcc/tree-inline.cc |  2 +-
 4 files changed, 14 insertions(+), 3 deletions(-)
  

Patch

diff --git a/gcc/cfgrtl.cc b/gcc/cfgrtl.cc
index abcb472e2a2..2a3f853eed5 100644
--- a/gcc/cfgrtl.cc
+++ b/gcc/cfgrtl.cc
@@ -4385,7 +4385,7 @@  duplicate_insn_chain (rtx_insn *from, rtx_insn *to,
 			  {
 			    gcc_assert
 			      (MR_DEPENDENCE_CLIQUE (op) <= cfun->last_clique);
-			    newc = ++cfun->last_clique;
+			    newc = get_new_clique (cfun);
 			  }
 			/* We cannot adjust MR_DEPENDENCE_CLIQUE in-place
 			   since MEM_EXPR is shared so make a copy and
diff --git a/gcc/function.h b/gcc/function.h
index 29846564bc6..833c35e3da6 100644
--- a/gcc/function.h
+++ b/gcc/function.h
@@ -518,6 +518,17 @@  set_loops_for_fn (struct function *fn, struct loops *loops)
   fn->x_current_loops = loops;
 }
 
+/* Get a new unique dependence clique or zero if none is left.  */
+
+inline unsigned short
+get_new_clique (function *fn)
+{
+  unsigned short clique = fn->last_clique + 1;
+  if (clique != 0)
+    fn->last_clique = clique;
+  return clique;
+}
+
 /* For backward compatibility... eventually these should all go away.  */
 #define current_function_funcdef_no (cfun->funcdef_no)
 
diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc
index a30a2de33a1..475ea5d99ef 100644
--- a/gcc/tree-cfg.cc
+++ b/gcc/tree-cfg.cc
@@ -6595,7 +6595,7 @@  gimple_duplicate_bb (basic_block bb, copy_bb_data *id)
 		if (!existed)
 		  {
 		    gcc_assert (MR_DEPENDENCE_CLIQUE (op) <= cfun->last_clique);
-		    newc = ++cfun->last_clique;
+		    newc = get_new_clique (cfun);
 		  }
 		MR_DEPENDENCE_CLIQUE (op) = newc;
 	      }
diff --git a/gcc/tree-inline.cc b/gcc/tree-inline.cc
index e6d553059e3..a4fc839a22d 100644
--- a/gcc/tree-inline.cc
+++ b/gcc/tree-inline.cc
@@ -1002,7 +1002,7 @@  remap_dependence_clique (copy_body_data *id, unsigned short clique)
       /* Clique 1 is reserved for local ones set by PTA.  */
       if (cfun->last_clique == 0)
 	cfun->last_clique = 1;
-      newc = ++cfun->last_clique;
+      newc = get_new_clique (cfun);
     }
   return newc;
 }