hash-map: reject empty-looking insertions
authorAlexandre Oliva <oliva@adacore.com>
Thu, 29 Dec 2022 17:33:04 +0000 (14:33 -0300)
committerAlexandre Oliva <oliva@gnu.org>
Thu, 29 Dec 2022 17:39:47 +0000 (14:39 -0300)
Check, after inserting entries, that they don't look empty.

for  gcc/ChangeLog

* hash-map.h (put, get_or_insert): Check that entry does not
look empty after insertion.

gcc/hash-map.h

index 457967f4bf1ae90020dffbffd80273af132d673f..63fa21cf37c5b35a94f8f359b6927a357b0d5f17 100644 (file)
@@ -169,11 +169,12 @@ public:
     {
       hash_entry *e = m_table.find_slot_with_hash (k, Traits::hash (k),
                                                   INSERT);
-      bool ins = hash_entry::is_empty (*e);
+      bool ins = Traits::is_empty (*e);
       if (ins)
        {
          e->m_key = k;
          new ((void *) &e->m_value) Value (v);
+         gcc_checking_assert (!Traits::is_empty (*e));
        }
       else
        e->m_value = v;
@@ -203,6 +204,7 @@ public:
        {
          e->m_key = k;
          new ((void *)&e->m_value) Value ();
+         gcc_checking_assert (!Traits::is_empty (*e));
        }
 
       if (existed != NULL)