]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
middle-end/112785 - guard against last_clique overflow
authorRichard Biener <rguenther@suse.de>
Mon, 4 Dec 2023 13:50:59 +0000 (14:50 +0100)
committerRichard Biener <rguenther@suse.de>
Mon, 4 Dec 2023 14:33:58 +0000 (15:33 +0100)
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.

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
gcc/function.h
gcc/tree-cfg.cc
gcc/tree-inline.cc

index abcb472e2a2d750befbd0be9a44fe39f21d25293..2a3f853eed59ba6ff1846cab7d90468e62a9ae9f 100644 (file)
@@ -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
index 29846564bc6f9579896baadd3fa7b9dab766f4d9..833c35e3da6066a9c58ce40cfaace2c21e09d450 100644 (file)
@@ -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)
 
index a30a2de33a10608e5dda2cf2a36b108a13781d13..475ea5d99effa380db04db775bde60f86924bdde 100644 (file)
@@ -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;
              }
index e6d553059e3ec132891b72cbb82d698dc4cffca3..a4fc839a22d5c7b98fd0a7e6923e270de1e5a893 100644 (file)
@@ -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;
 }