]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gimple: sccopy: Don't increment i after vec::unordered_remove()
authorFilip Kastl <fkastl@suse.cz>
Thu, 20 Mar 2025 10:54:59 +0000 (11:54 +0100)
committerFilip Kastl <fkastl@suse.cz>
Fri, 21 Mar 2025 13:00:59 +0000 (14:00 +0100)
I increment the index variable in a loop even when I do
vec::unordered_remove() which causes the vector traversal to miss some
elements.  Mikael notified me of this mistake I made in my last patch.

gcc/ChangeLog:

* gimple-ssa-sccopy.cc (scc_copy_prop::propagate): Don't
increment after vec::unordered_remove().

Reported-by: Mikael Morin <mikael@gcc.gnu.org>
Signed-off-by: Filip Kastl <fkastl@suse.cz>
(cherry picked from commit a1363f8dd8037d40e9fbf04c2ba8d6d3e7e5c269)

gcc/gimple-ssa-sccopy.cc

index d4d06f3b13e7ae1a6be88780ad082b6a06aa7db8..f7e121992e5fe398f510ac6c049c0beb19b31df5 100644 (file)
@@ -554,9 +554,11 @@ sccopy_propagate ()
         get removed.  That means parts of CFG get removed.  Those may
         contain copy statements.  For that reason we prune SCCs here.  */
       unsigned i;
-      for (i = 0; i < scc.length (); i++)
+      for (i = 0; i < scc.length ();)
        if (gimple_bb (scc[i]) == NULL)
          scc.unordered_remove (i);
+       else
+         i++;
       if (scc.is_empty ())
        {
          scc.release ();