public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-3159] Fix off-by-one error in try_merge_with
@ 2021-08-26 13:34 Jan Hubicka
  0 siblings, 0 replies; only message in thread
From: Jan Hubicka @ 2021-08-26 13:34 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:f075b8c5adcf9cb6336563c472c8d624c54184db

commit r12-3159-gf075b8c5adcf9cb6336563c472c8d624c54184db
Author: Jan Hubicka <hubicka@ucw.cz>
Date:   Thu Aug 26 15:33:56 2021 +0200

    Fix off-by-one error in try_merge_with
    
    gcc/ChangeLog:
    
            * ipa-modref-tree.h (modref_ref_node::verify): New member
            functoin.
            (modref_ref_node::insert): Use it.
            (modref_ref_node::try_mere_with): Fix off by one error.

Diff:
---
 gcc/ipa-modref-tree.h | 29 ++++++++++++++++++++++++-----
 1 file changed, 24 insertions(+), 5 deletions(-)

diff --git a/gcc/ipa-modref-tree.h b/gcc/ipa-modref-tree.h
index 6f6932f0875..4edec4efded 100644
--- a/gcc/ipa-modref-tree.h
+++ b/gcc/ipa-modref-tree.h
@@ -322,6 +322,20 @@ struct GTY((user)) modref_ref_node
     every_access = true;
   }
 
+  /* Verify that list does not contain redundant accesses.  */
+  void verify ()
+  {
+    size_t i, i2;
+    modref_access_node *a, *a2;
+
+    FOR_EACH_VEC_SAFE_ELT (accesses, i, a)
+      {
+	FOR_EACH_VEC_SAFE_ELT (accesses, i2, a2)
+	  if (i != i2)
+	    gcc_assert (!a->contains (*a2));
+      }
+  }
+
   /* Insert access with OFFSET and SIZE.
      Collapse tree if it has more than MAX_ACCESSES entries.
      If RECORD_ADJUSTMENTs is true avoid too many interval extensions.
@@ -337,6 +351,9 @@ struct GTY((user)) modref_ref_node
     size_t i;
     modref_access_node *a2;
 
+    if (flag_checking)
+      verify ();
+
     if (!a.useful_p ())
       {
 	if (!every_access)
@@ -392,13 +409,15 @@ private:
     size_t i;
 
     FOR_EACH_VEC_SAFE_ELT (accesses, i, a2)
-      if (i != index)
-	if ((*accesses)[index].contains (*a2)
-	    || (*accesses)[index].merge (*a2, false))
+      if (i != index
+	  && ((*accesses)[index].contains (*a2)
+	      || (*accesses)[index].merge (*a2, false)))
 	{
-	  if (index == accesses->length () - 1)
-	    index = i;
 	  accesses->unordered_remove (i);
+	  if (index == accesses->length ())
+	    index = i;
+	  else
+	    i--;
 	}
   }
 };


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-08-26 13:34 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-26 13:34 [gcc r12-3159] Fix off-by-one error in try_merge_with Jan Hubicka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).