public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/aoliva/heads/testme)] check hash table insertions
@ 2022-12-28 6:47 Alexandre Oliva
0 siblings, 0 replies; 6+ messages in thread
From: Alexandre Oliva @ 2022-12-28 6:47 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:bef79445538708ecd5b29e453f3b0250c885b4d8
commit bef79445538708ecd5b29e453f3b0250c885b4d8
Author: Alexandre Oliva <oliva@gnu.org>
Date: Wed Dec 28 02:21:46 2022 -0300
check hash table insertions
Diff:
---
gcc/hash-table.h | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 57 insertions(+), 3 deletions(-)
diff --git a/gcc/hash-table.h b/gcc/hash-table.h
index f4bda610232..cc6d41e1e23 100644
--- a/gcc/hash-table.h
+++ b/gcc/hash-table.h
@@ -495,6 +495,7 @@ public:
{
if (Lazy && m_entries == NULL)
return iterator ();
+ check_complete_insertion ();
iterator iter (m_entries, m_entries + m_size);
iter.slide ();
return iter;
@@ -551,8 +552,37 @@ private:
Descriptor::mark_empty (v);
}
+ void check_complete_insertion () const
+ {
+#if CHECKING_P
+ if (!m_inserting_slot)
+ return;
+
+ gcc_checking_assert (m_inserting_slot >= &m_entries[0]
+ && m_inserting_slot < &m_entries[m_size]);
+
+ if (!is_empty (*m_inserting_slot))
+ m_inserting_slot = NULL;
+ else
+ gcc_unreachable ();
+#endif
+ }
+
+ value_type *check_insert_slot (value_type *ret)
+ {
+#if CHECKING_P
+ gcc_checking_assert (is_empty (*ret));
+ m_inserting_slot = ret;
+#endif
+ return ret;
+ }
+
+#if CHECKING_P
+ mutable value_type *m_inserting_slot;
+#endif
+
/* Table itself. */
- typename Descriptor::value_type *m_entries;
+ value_type *m_entries;
size_t m_size;
@@ -607,6 +637,9 @@ hash_table<Descriptor, Lazy, Allocator>::hash_table (size_t size, bool ggc,
ATTRIBUTE_UNUSED,
mem_alloc_origin origin
MEM_STAT_DECL) :
+#if CHECKING_P
+ m_inserting_slot (0),
+#endif
m_n_elements (0), m_n_deleted (0), m_searches (0), m_collisions (0),
m_ggc (ggc), m_sanitize_eq_and_hash (sanitize_eq_and_hash)
#if GATHER_STATISTICS
@@ -639,6 +672,9 @@ hash_table<Descriptor, Lazy, Allocator>::hash_table (const hash_table &h,
ATTRIBUTE_UNUSED,
mem_alloc_origin origin
MEM_STAT_DECL) :
+#if CHECKING_P
+ m_inserting_slot (0),
+#endif
m_n_elements (h.m_n_elements), m_n_deleted (h.m_n_deleted),
m_searches (0), m_collisions (0), m_ggc (ggc),
m_sanitize_eq_and_hash (sanitize_eq_and_hash)
@@ -646,6 +682,8 @@ hash_table<Descriptor, Lazy, Allocator>::hash_table (const hash_table &h,
, m_gather_mem_stats (gather_mem_stats)
#endif
{
+ h.check_complete_insertion ();
+
size_t size = h.m_size;
if (m_gather_mem_stats)
@@ -675,6 +713,8 @@ template<typename Descriptor, bool Lazy,
template<typename Type> class Allocator>
hash_table<Descriptor, Lazy, Allocator>::~hash_table ()
{
+ check_complete_insertion ();
+
if (!Lazy || m_entries)
{
for (size_t i = m_size - 1; i < m_size; i--)
@@ -778,6 +818,8 @@ template<typename Descriptor, bool Lazy,
void
hash_table<Descriptor, Lazy, Allocator>::expand ()
{
+ check_complete_insertion ();
+
value_type *oentries = m_entries;
unsigned int oindex = m_size_prime_index;
size_t osize = size ();
@@ -853,6 +895,8 @@ template<typename Descriptor, bool Lazy,
void
hash_table<Descriptor, Lazy, Allocator>::empty_slow ()
{
+ check_complete_insertion ();
+
size_t size = m_size;
size_t nsize = size;
value_type *entries = m_entries;
@@ -901,6 +945,8 @@ template<typename Descriptor, bool Lazy,
void
hash_table<Descriptor, Lazy, Allocator>::clear_slot (value_type *slot)
{
+ check_complete_insertion ();
+
gcc_checking_assert (!(slot < m_entries || slot >= m_entries + size ()
|| is_empty (*slot) || is_deleted (*slot)));
@@ -927,6 +973,8 @@ hash_table<Descriptor, Lazy, Allocator>
if (Lazy && m_entries == NULL)
m_entries = alloc_entries (size);
+ check_complete_insertion ();
+
#if CHECKING_P
if (m_sanitize_eq_and_hash)
verify (comparable, hash);
@@ -976,6 +1024,8 @@ hash_table<Descriptor, Lazy, Allocator>
}
if (insert == INSERT && m_size * 3 <= m_n_elements * 4)
expand ();
+ else
+ check_complete_insertion ();
#if CHECKING_P
if (m_sanitize_eq_and_hash)
@@ -1022,11 +1072,11 @@ hash_table<Descriptor, Lazy, Allocator>
{
m_n_deleted--;
mark_empty (*first_deleted_slot);
- return first_deleted_slot;
+ return check_insert_slot (first_deleted_slot);
}
m_n_elements++;
- return &m_entries[index];
+ return check_insert_slot (&m_entries[index]);
}
/* Verify that all existing elements in the hash table which are
@@ -1068,6 +1118,8 @@ void
hash_table<Descriptor, Lazy, Allocator>
::remove_elt_with_hash (const compare_type &comparable, hashval_t hash)
{
+ check_complete_insertion ();
+
value_type *slot = find_slot_with_hash (comparable, hash, NO_INSERT);
if (slot == NULL)
return;
@@ -1094,6 +1146,8 @@ hash_table<Descriptor, Lazy, Allocator>::traverse_noresize (Argument argument)
if (Lazy && m_entries == NULL)
return;
+ check_complete_insertion ();
+
value_type *slot = m_entries;
value_type *limit = slot + size ();
^ permalink raw reply [flat|nested] 6+ messages in thread
* [gcc(refs/users/aoliva/heads/testme)] check hash table insertions
@ 2022-12-28 10:28 Alexandre Oliva
0 siblings, 0 replies; 6+ messages in thread
From: Alexandre Oliva @ 2022-12-28 10:28 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:6ff51db0a9efd81fca14042ffacd6f343a72eac4
commit 6ff51db0a9efd81fca14042ffacd6f343a72eac4
Author: Alexandre Oliva <oliva@gnu.org>
Date: Wed Dec 28 02:21:46 2022 -0300
check hash table insertions
Diff:
---
gcc/hash-table.h | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 60 insertions(+), 3 deletions(-)
diff --git a/gcc/hash-table.h b/gcc/hash-table.h
index f4bda610232..33753d04b7b 100644
--- a/gcc/hash-table.h
+++ b/gcc/hash-table.h
@@ -495,6 +495,7 @@ public:
{
if (Lazy && m_entries == NULL)
return iterator ();
+ check_complete_insertion ();
iterator iter (m_entries, m_entries + m_size);
iter.slide ();
return iter;
@@ -551,8 +552,39 @@ private:
Descriptor::mark_empty (v);
}
+public:
+ void check_complete_insertion () const
+ {
+#if CHECKING_P
+ if (!m_inserting_slot)
+ return;
+
+ gcc_checking_assert (m_inserting_slot >= &m_entries[0]
+ && m_inserting_slot < &m_entries[m_size]);
+
+ if (!is_empty (*m_inserting_slot))
+ m_inserting_slot = NULL;
+ else
+ gcc_unreachable ();
+#endif
+ }
+
+private:
+ value_type *check_insert_slot (value_type *ret)
+ {
+#if CHECKING_P
+ gcc_checking_assert (is_empty (*ret));
+ m_inserting_slot = ret;
+#endif
+ return ret;
+ }
+
+#if CHECKING_P
+ mutable value_type *m_inserting_slot;
+#endif
+
/* Table itself. */
- typename Descriptor::value_type *m_entries;
+ value_type *m_entries;
size_t m_size;
@@ -607,6 +639,9 @@ hash_table<Descriptor, Lazy, Allocator>::hash_table (size_t size, bool ggc,
ATTRIBUTE_UNUSED,
mem_alloc_origin origin
MEM_STAT_DECL) :
+#if CHECKING_P
+ m_inserting_slot (0),
+#endif
m_n_elements (0), m_n_deleted (0), m_searches (0), m_collisions (0),
m_ggc (ggc), m_sanitize_eq_and_hash (sanitize_eq_and_hash)
#if GATHER_STATISTICS
@@ -639,6 +674,9 @@ hash_table<Descriptor, Lazy, Allocator>::hash_table (const hash_table &h,
ATTRIBUTE_UNUSED,
mem_alloc_origin origin
MEM_STAT_DECL) :
+#if CHECKING_P
+ m_inserting_slot (0),
+#endif
m_n_elements (h.m_n_elements), m_n_deleted (h.m_n_deleted),
m_searches (0), m_collisions (0), m_ggc (ggc),
m_sanitize_eq_and_hash (sanitize_eq_and_hash)
@@ -646,6 +684,8 @@ hash_table<Descriptor, Lazy, Allocator>::hash_table (const hash_table &h,
, m_gather_mem_stats (gather_mem_stats)
#endif
{
+ h.check_complete_insertion ();
+
size_t size = h.m_size;
if (m_gather_mem_stats)
@@ -675,6 +715,8 @@ template<typename Descriptor, bool Lazy,
template<typename Type> class Allocator>
hash_table<Descriptor, Lazy, Allocator>::~hash_table ()
{
+ check_complete_insertion ();
+
if (!Lazy || m_entries)
{
for (size_t i = m_size - 1; i < m_size; i--)
@@ -778,6 +820,8 @@ template<typename Descriptor, bool Lazy,
void
hash_table<Descriptor, Lazy, Allocator>::expand ()
{
+ check_complete_insertion ();
+
value_type *oentries = m_entries;
unsigned int oindex = m_size_prime_index;
size_t osize = size ();
@@ -853,6 +897,8 @@ template<typename Descriptor, bool Lazy,
void
hash_table<Descriptor, Lazy, Allocator>::empty_slow ()
{
+ check_complete_insertion ();
+
size_t size = m_size;
size_t nsize = size;
value_type *entries = m_entries;
@@ -901,6 +947,8 @@ template<typename Descriptor, bool Lazy,
void
hash_table<Descriptor, Lazy, Allocator>::clear_slot (value_type *slot)
{
+ check_complete_insertion ();
+
gcc_checking_assert (!(slot < m_entries || slot >= m_entries + size ()
|| is_empty (*slot) || is_deleted (*slot)));
@@ -927,6 +975,8 @@ hash_table<Descriptor, Lazy, Allocator>
if (Lazy && m_entries == NULL)
m_entries = alloc_entries (size);
+ check_complete_insertion ();
+
#if CHECKING_P
if (m_sanitize_eq_and_hash)
verify (comparable, hash);
@@ -976,6 +1026,8 @@ hash_table<Descriptor, Lazy, Allocator>
}
if (insert == INSERT && m_size * 3 <= m_n_elements * 4)
expand ();
+ else
+ check_complete_insertion ();
#if CHECKING_P
if (m_sanitize_eq_and_hash)
@@ -1022,11 +1074,11 @@ hash_table<Descriptor, Lazy, Allocator>
{
m_n_deleted--;
mark_empty (*first_deleted_slot);
- return first_deleted_slot;
+ return check_insert_slot (first_deleted_slot);
}
m_n_elements++;
- return &m_entries[index];
+ return check_insert_slot (&m_entries[index]);
}
/* Verify that all existing elements in the hash table which are
@@ -1068,6 +1120,8 @@ void
hash_table<Descriptor, Lazy, Allocator>
::remove_elt_with_hash (const compare_type &comparable, hashval_t hash)
{
+ check_complete_insertion ();
+
value_type *slot = find_slot_with_hash (comparable, hash, NO_INSERT);
if (slot == NULL)
return;
@@ -1094,6 +1148,8 @@ hash_table<Descriptor, Lazy, Allocator>::traverse_noresize (Argument argument)
if (Lazy && m_entries == NULL)
return;
+ check_complete_insertion ();
+
value_type *slot = m_entries;
value_type *limit = slot + size ();
@@ -1210,6 +1266,7 @@ template<typename D>
static void
gt_pch_nx (hash_table<D> *h)
{
+ h->check_complete_insertion ();
bool success
= gt_pch_note_object (h->m_entries, h, hashtab_entry_note_pointers<D>);
gcc_checking_assert (success);
^ permalink raw reply [flat|nested] 6+ messages in thread
* [gcc(refs/users/aoliva/heads/testme)] check hash table insertions
@ 2022-12-28 8:06 Alexandre Oliva
0 siblings, 0 replies; 6+ messages in thread
From: Alexandre Oliva @ 2022-12-28 8:06 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:29d81e0ecc903d1d75e7c59c19474a6ba6bb497b
commit 29d81e0ecc903d1d75e7c59c19474a6ba6bb497b
Author: Alexandre Oliva <oliva@gnu.org>
Date: Wed Dec 28 02:21:46 2022 -0300
check hash table insertions
Diff:
---
gcc/hash-table.h | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 60 insertions(+), 3 deletions(-)
diff --git a/gcc/hash-table.h b/gcc/hash-table.h
index f4bda610232..5aa26f6768e 100644
--- a/gcc/hash-table.h
+++ b/gcc/hash-table.h
@@ -495,6 +495,7 @@ public:
{
if (Lazy && m_entries == NULL)
return iterator ();
+ check_complete_insertion ();
iterator iter (m_entries, m_entries + m_size);
iter.slide ();
return iter;
@@ -551,8 +552,39 @@ private:
Descriptor::mark_empty (v);
}
+public:
+ void check_complete_insertion () const
+ {
+#if CHECKING_P
+ if (!m_inserting_slot)
+ return;
+
+ gcc_checking_assert (m_inserting_slot >= &m_entries[0]
+ && m_inserting_slot < &m_entries[m_size]);
+
+ if (!is_empty (*m_inserting_slot))
+ m_inserting_slot = NULL;
+ else
+ gcc_unreachable ();
+#endif
+ }
+
+private:
+ value_type *check_insert_slot (value_type *ret)
+ {
+#if CHECKING_P
+ gcc_checking_assert (is_empty (*ret));
+ m_inserting_slot = ret;
+#endif
+ return ret;
+ }
+
+#if CHECKING_P
+ mutable value_type * GTY((skip)) m_inserting_slot;
+#endif
+
/* Table itself. */
- typename Descriptor::value_type *m_entries;
+ value_type *m_entries;
size_t m_size;
@@ -607,6 +639,9 @@ hash_table<Descriptor, Lazy, Allocator>::hash_table (size_t size, bool ggc,
ATTRIBUTE_UNUSED,
mem_alloc_origin origin
MEM_STAT_DECL) :
+#if CHECKING_P
+ m_inserting_slot (0),
+#endif
m_n_elements (0), m_n_deleted (0), m_searches (0), m_collisions (0),
m_ggc (ggc), m_sanitize_eq_and_hash (sanitize_eq_and_hash)
#if GATHER_STATISTICS
@@ -639,6 +674,9 @@ hash_table<Descriptor, Lazy, Allocator>::hash_table (const hash_table &h,
ATTRIBUTE_UNUSED,
mem_alloc_origin origin
MEM_STAT_DECL) :
+#if CHECKING_P
+ m_inserting_slot (0),
+#endif
m_n_elements (h.m_n_elements), m_n_deleted (h.m_n_deleted),
m_searches (0), m_collisions (0), m_ggc (ggc),
m_sanitize_eq_and_hash (sanitize_eq_and_hash)
@@ -646,6 +684,8 @@ hash_table<Descriptor, Lazy, Allocator>::hash_table (const hash_table &h,
, m_gather_mem_stats (gather_mem_stats)
#endif
{
+ h.check_complete_insertion ();
+
size_t size = h.m_size;
if (m_gather_mem_stats)
@@ -675,6 +715,8 @@ template<typename Descriptor, bool Lazy,
template<typename Type> class Allocator>
hash_table<Descriptor, Lazy, Allocator>::~hash_table ()
{
+ check_complete_insertion ();
+
if (!Lazy || m_entries)
{
for (size_t i = m_size - 1; i < m_size; i--)
@@ -778,6 +820,8 @@ template<typename Descriptor, bool Lazy,
void
hash_table<Descriptor, Lazy, Allocator>::expand ()
{
+ check_complete_insertion ();
+
value_type *oentries = m_entries;
unsigned int oindex = m_size_prime_index;
size_t osize = size ();
@@ -853,6 +897,8 @@ template<typename Descriptor, bool Lazy,
void
hash_table<Descriptor, Lazy, Allocator>::empty_slow ()
{
+ check_complete_insertion ();
+
size_t size = m_size;
size_t nsize = size;
value_type *entries = m_entries;
@@ -901,6 +947,8 @@ template<typename Descriptor, bool Lazy,
void
hash_table<Descriptor, Lazy, Allocator>::clear_slot (value_type *slot)
{
+ check_complete_insertion ();
+
gcc_checking_assert (!(slot < m_entries || slot >= m_entries + size ()
|| is_empty (*slot) || is_deleted (*slot)));
@@ -927,6 +975,8 @@ hash_table<Descriptor, Lazy, Allocator>
if (Lazy && m_entries == NULL)
m_entries = alloc_entries (size);
+ check_complete_insertion ();
+
#if CHECKING_P
if (m_sanitize_eq_and_hash)
verify (comparable, hash);
@@ -976,6 +1026,8 @@ hash_table<Descriptor, Lazy, Allocator>
}
if (insert == INSERT && m_size * 3 <= m_n_elements * 4)
expand ();
+ else
+ check_complete_insertion ();
#if CHECKING_P
if (m_sanitize_eq_and_hash)
@@ -1022,11 +1074,11 @@ hash_table<Descriptor, Lazy, Allocator>
{
m_n_deleted--;
mark_empty (*first_deleted_slot);
- return first_deleted_slot;
+ return check_insert_slot (first_deleted_slot);
}
m_n_elements++;
- return &m_entries[index];
+ return check_insert_slot (&m_entries[index]);
}
/* Verify that all existing elements in the hash table which are
@@ -1068,6 +1120,8 @@ void
hash_table<Descriptor, Lazy, Allocator>
::remove_elt_with_hash (const compare_type &comparable, hashval_t hash)
{
+ check_complete_insertion ();
+
value_type *slot = find_slot_with_hash (comparable, hash, NO_INSERT);
if (slot == NULL)
return;
@@ -1094,6 +1148,8 @@ hash_table<Descriptor, Lazy, Allocator>::traverse_noresize (Argument argument)
if (Lazy && m_entries == NULL)
return;
+ check_complete_insertion ();
+
value_type *slot = m_entries;
value_type *limit = slot + size ();
@@ -1227,6 +1283,7 @@ template<typename D>
static inline void
gt_pch_nx (hash_table<D> *h, gt_pointer_operator op, void *cookie)
{
+ h->check_complete_insertion ();
op (&h->m_entries, NULL, cookie);
}
^ permalink raw reply [flat|nested] 6+ messages in thread
* [gcc(refs/users/aoliva/heads/testme)] check hash table insertions
@ 2022-12-28 6:46 Alexandre Oliva
0 siblings, 0 replies; 6+ messages in thread
From: Alexandre Oliva @ 2022-12-28 6:46 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:4110f0851c28b66774ed70e5472b48f8a7acca93
commit 4110f0851c28b66774ed70e5472b48f8a7acca93
Author: Alexandre Oliva <oliva@gnu.org>
Date: Wed Dec 28 02:21:46 2022 -0300
check hash table insertions
Diff:
---
gcc/hash-table.h | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 59 insertions(+), 3 deletions(-)
diff --git a/gcc/hash-table.h b/gcc/hash-table.h
index f4bda610232..42bd0d0cebb 100644
--- a/gcc/hash-table.h
+++ b/gcc/hash-table.h
@@ -495,6 +495,7 @@ public:
{
if (Lazy && m_entries == NULL)
return iterator ();
+ check_complete_insertion ();
iterator iter (m_entries, m_entries + m_size);
iter.slide ();
return iter;
@@ -551,8 +552,37 @@ private:
Descriptor::mark_empty (v);
}
+ void check_complete_insertion () const
+ {
+#if CHECKING_P
+ if (!m_inserting_slot)
+ return;
+
+ gcc_checking_assert (m_inserting_slot >= &m_entries[0]
+ && m_inserting_slot < &m_entries[m_size]);
+
+ if (!is_empty (*m_inserting_slot))
+ m_inserting_slot = NULL;
+ else
+ gcc_unreachable ();
+#endif
+ }
+
+ value_type *check_insert_slot (value_type *ret)
+ {
+#if CHECKING_P
+ gcc_checking_assert (is_empty (*ret));
+ m_inserting_slot = ret;
+#endif
+ return ret;
+ }
+
+#if CHECKING_P
+ mutable value_type *m_inserting_slot;
+#endif
+
/* Table itself. */
- typename Descriptor::value_type *m_entries;
+ value_type *m_entries;
size_t m_size;
@@ -607,6 +637,9 @@ hash_table<Descriptor, Lazy, Allocator>::hash_table (size_t size, bool ggc,
ATTRIBUTE_UNUSED,
mem_alloc_origin origin
MEM_STAT_DECL) :
+#if CHECKING_P
+ m_inserting_slot (0),
+#endif
m_n_elements (0), m_n_deleted (0), m_searches (0), m_collisions (0),
m_ggc (ggc), m_sanitize_eq_and_hash (sanitize_eq_and_hash)
#if GATHER_STATISTICS
@@ -639,6 +672,9 @@ hash_table<Descriptor, Lazy, Allocator>::hash_table (const hash_table &h,
ATTRIBUTE_UNUSED,
mem_alloc_origin origin
MEM_STAT_DECL) :
+#if CHECKING_P
+ m_inserting_slot (0),
+#endif
m_n_elements (h.m_n_elements), m_n_deleted (h.m_n_deleted),
m_searches (0), m_collisions (0), m_ggc (ggc),
m_sanitize_eq_and_hash (sanitize_eq_and_hash)
@@ -646,6 +682,10 @@ hash_table<Descriptor, Lazy, Allocator>::hash_table (const hash_table &h,
, m_gather_mem_stats (gather_mem_stats)
#endif
{
+#if CHECKING_P
+ h.check_complete_insertion ();
+#endif
+
size_t size = h.m_size;
if (m_gather_mem_stats)
@@ -675,6 +715,8 @@ template<typename Descriptor, bool Lazy,
template<typename Type> class Allocator>
hash_table<Descriptor, Lazy, Allocator>::~hash_table ()
{
+ check_complete_insertion ();
+
if (!Lazy || m_entries)
{
for (size_t i = m_size - 1; i < m_size; i--)
@@ -778,6 +820,8 @@ template<typename Descriptor, bool Lazy,
void
hash_table<Descriptor, Lazy, Allocator>::expand ()
{
+ check_complete_insertion ();
+
value_type *oentries = m_entries;
unsigned int oindex = m_size_prime_index;
size_t osize = size ();
@@ -853,6 +897,8 @@ template<typename Descriptor, bool Lazy,
void
hash_table<Descriptor, Lazy, Allocator>::empty_slow ()
{
+ check_complete_insertion ();
+
size_t size = m_size;
size_t nsize = size;
value_type *entries = m_entries;
@@ -901,6 +947,8 @@ template<typename Descriptor, bool Lazy,
void
hash_table<Descriptor, Lazy, Allocator>::clear_slot (value_type *slot)
{
+ check_complete_insertion ();
+
gcc_checking_assert (!(slot < m_entries || slot >= m_entries + size ()
|| is_empty (*slot) || is_deleted (*slot)));
@@ -927,6 +975,8 @@ hash_table<Descriptor, Lazy, Allocator>
if (Lazy && m_entries == NULL)
m_entries = alloc_entries (size);
+ check_complete_insertion ();
+
#if CHECKING_P
if (m_sanitize_eq_and_hash)
verify (comparable, hash);
@@ -976,6 +1026,8 @@ hash_table<Descriptor, Lazy, Allocator>
}
if (insert == INSERT && m_size * 3 <= m_n_elements * 4)
expand ();
+ else
+ check_complete_insertion ();
#if CHECKING_P
if (m_sanitize_eq_and_hash)
@@ -1022,11 +1074,11 @@ hash_table<Descriptor, Lazy, Allocator>
{
m_n_deleted--;
mark_empty (*first_deleted_slot);
- return first_deleted_slot;
+ return check_insert_slot (first_deleted_slot);
}
m_n_elements++;
- return &m_entries[index];
+ return check_insert_slot (&m_entries[index]);
}
/* Verify that all existing elements in the hash table which are
@@ -1068,6 +1120,8 @@ void
hash_table<Descriptor, Lazy, Allocator>
::remove_elt_with_hash (const compare_type &comparable, hashval_t hash)
{
+ check_complete_insertion ();
+
value_type *slot = find_slot_with_hash (comparable, hash, NO_INSERT);
if (slot == NULL)
return;
@@ -1094,6 +1148,8 @@ hash_table<Descriptor, Lazy, Allocator>::traverse_noresize (Argument argument)
if (Lazy && m_entries == NULL)
return;
+ check_complete_insertion ();
+
value_type *slot = m_entries;
value_type *limit = slot + size ();
^ permalink raw reply [flat|nested] 6+ messages in thread
* [gcc(refs/users/aoliva/heads/testme)] check hash table insertions
@ 2022-12-28 6:44 Alexandre Oliva
0 siblings, 0 replies; 6+ messages in thread
From: Alexandre Oliva @ 2022-12-28 6:44 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:221a1409df828441efd989ffbf7db0961a1ebf44
commit 221a1409df828441efd989ffbf7db0961a1ebf44
Author: Alexandre Oliva <oliva@gnu.org>
Date: Wed Dec 28 02:21:46 2022 -0300
check hash table insertions
Diff:
---
gcc/hash-table.h | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 59 insertions(+), 3 deletions(-)
diff --git a/gcc/hash-table.h b/gcc/hash-table.h
index f4bda610232..4554ff45bcb 100644
--- a/gcc/hash-table.h
+++ b/gcc/hash-table.h
@@ -495,6 +495,7 @@ public:
{
if (Lazy && m_entries == NULL)
return iterator ();
+ check_complete_insertion ();
iterator iter (m_entries, m_entries + m_size);
iter.slide ();
return iter;
@@ -551,8 +552,37 @@ private:
Descriptor::mark_empty (v);
}
+ void check_complete_insertion () const
+ {
+#if CHECKING_P
+ if (!m_inserting_slot)
+ return;
+
+ gcc_checking_assert (m_inserting_slot >= &m_entries[0]
+ && m_inserting_slot < &m_entries[m_size]);
+
+ if (!is_empty (*m_inserting_slot))
+ m_inserting_slot = NULL;
+ else
+ gcc_unreachable ();
+#endif
+ }
+
+ value_type *check_insert_slot (value_type *ret)
+ {
+#if CHECKING_P
+ gcc_checking_assert (is_empty (*ret));
+ m_inserting_slot = ret;
+#endif
+ return ret;
+ }
+
+#if CHECKING_P
+ mutable value_type *m_inserting_slot;
+#endif
+
/* Table itself. */
- typename Descriptor::value_type *m_entries;
+ value_type *m_entries;
size_t m_size;
@@ -607,6 +637,9 @@ hash_table<Descriptor, Lazy, Allocator>::hash_table (size_t size, bool ggc,
ATTRIBUTE_UNUSED,
mem_alloc_origin origin
MEM_STAT_DECL) :
+#if CHECKING_P
+ m_inserting_slot (0),
+#endif
m_n_elements (0), m_n_deleted (0), m_searches (0), m_collisions (0),
m_ggc (ggc), m_sanitize_eq_and_hash (sanitize_eq_and_hash)
#if GATHER_STATISTICS
@@ -639,6 +672,9 @@ hash_table<Descriptor, Lazy, Allocator>::hash_table (const hash_table &h,
ATTRIBUTE_UNUSED,
mem_alloc_origin origin
MEM_STAT_DECL) :
+#if CHECKING_P
+ m_inserting_slot (0),
+#endif
m_n_elements (h.m_n_elements), m_n_deleted (h.m_n_deleted),
m_searches (0), m_collisions (0), m_ggc (ggc),
m_sanitize_eq_and_hash (sanitize_eq_and_hash)
@@ -646,6 +682,10 @@ hash_table<Descriptor, Lazy, Allocator>::hash_table (const hash_table &h,
, m_gather_mem_stats (gather_mem_stats)
#endif
{
+#if CHECKING_P
+ gcc_checking_assert (!h.check_complete_insertion ());
+#endif
+
size_t size = h.m_size;
if (m_gather_mem_stats)
@@ -675,6 +715,8 @@ template<typename Descriptor, bool Lazy,
template<typename Type> class Allocator>
hash_table<Descriptor, Lazy, Allocator>::~hash_table ()
{
+ check_complete_insertion ();
+
if (!Lazy || m_entries)
{
for (size_t i = m_size - 1; i < m_size; i--)
@@ -778,6 +820,8 @@ template<typename Descriptor, bool Lazy,
void
hash_table<Descriptor, Lazy, Allocator>::expand ()
{
+ check_complete_insertion ();
+
value_type *oentries = m_entries;
unsigned int oindex = m_size_prime_index;
size_t osize = size ();
@@ -853,6 +897,8 @@ template<typename Descriptor, bool Lazy,
void
hash_table<Descriptor, Lazy, Allocator>::empty_slow ()
{
+ check_complete_insertion ();
+
size_t size = m_size;
size_t nsize = size;
value_type *entries = m_entries;
@@ -901,6 +947,8 @@ template<typename Descriptor, bool Lazy,
void
hash_table<Descriptor, Lazy, Allocator>::clear_slot (value_type *slot)
{
+ check_complete_insertion ();
+
gcc_checking_assert (!(slot < m_entries || slot >= m_entries + size ()
|| is_empty (*slot) || is_deleted (*slot)));
@@ -927,6 +975,8 @@ hash_table<Descriptor, Lazy, Allocator>
if (Lazy && m_entries == NULL)
m_entries = alloc_entries (size);
+ check_complete_insertion ();
+
#if CHECKING_P
if (m_sanitize_eq_and_hash)
verify (comparable, hash);
@@ -976,6 +1026,8 @@ hash_table<Descriptor, Lazy, Allocator>
}
if (insert == INSERT && m_size * 3 <= m_n_elements * 4)
expand ();
+ else
+ check_complete_insertion ();
#if CHECKING_P
if (m_sanitize_eq_and_hash)
@@ -1022,11 +1074,11 @@ hash_table<Descriptor, Lazy, Allocator>
{
m_n_deleted--;
mark_empty (*first_deleted_slot);
- return first_deleted_slot;
+ return check_insert_slot (first_deleted_slot);
}
m_n_elements++;
- return &m_entries[index];
+ return check_insert_slot (&m_entries[index]);
}
/* Verify that all existing elements in the hash table which are
@@ -1068,6 +1120,8 @@ void
hash_table<Descriptor, Lazy, Allocator>
::remove_elt_with_hash (const compare_type &comparable, hashval_t hash)
{
+ check_complete_insertion ();
+
value_type *slot = find_slot_with_hash (comparable, hash, NO_INSERT);
if (slot == NULL)
return;
@@ -1094,6 +1148,8 @@ hash_table<Descriptor, Lazy, Allocator>::traverse_noresize (Argument argument)
if (Lazy && m_entries == NULL)
return;
+ check_complete_insertion ();
+
value_type *slot = m_entries;
value_type *limit = slot + size ();
^ permalink raw reply [flat|nested] 6+ messages in thread
* [gcc(refs/users/aoliva/heads/testme)] check hash table insertions
@ 2022-12-28 5:24 Alexandre Oliva
0 siblings, 0 replies; 6+ messages in thread
From: Alexandre Oliva @ 2022-12-28 5:24 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:3469419de0b7ebabf28d3ef48ecb3707f75504bb
commit 3469419de0b7ebabf28d3ef48ecb3707f75504bb
Author: Alexandre Oliva <oliva@gnu.org>
Date: Wed Dec 28 02:21:46 2022 -0300
check hash table insertions
Diff:
---
gcc/hash-table.h | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 59 insertions(+), 3 deletions(-)
diff --git a/gcc/hash-table.h b/gcc/hash-table.h
index f4bda610232..34640119c38 100644
--- a/gcc/hash-table.h
+++ b/gcc/hash-table.h
@@ -495,6 +495,7 @@ public:
{
if (Lazy && m_entries == NULL)
return iterator ();
+ check_complete_insertion ();
iterator iter (m_entries, m_entries + m_size);
iter.slide ();
return iter;
@@ -551,8 +552,37 @@ private:
Descriptor::mark_empty (v);
}
+ void check_complete_insertion () const
+ {
+#if CHECKING_P
+ if (!m_inserting_slot)
+ return;
+
+ gcc_checking_assert (m_inserting_slot >= &m_entries[0]
+ && m_inserting_slot < &m_entries[m_size]);
+
+ if (!is_empty (*m_inserting_slot))
+ m_inserting_slot = NULL;
+ else
+ gcc_unreachable ();
+#endif
+ }
+
+ value_type *check_insert_slot (value_type *ret)
+ {
+#if CHECKING_P
+ gcc_checking_assert (is_empty (*ret));
+ m_inserting_slot = ret;
+#endif
+ return ret;
+ }
+
+#if CHECKING_P
+ mutable value_type *m_inserting_slot;
+#endif
+
/* Table itself. */
- typename Descriptor::value_type *m_entries;
+ value_type *m_entries;
size_t m_size;
@@ -607,6 +637,9 @@ hash_table<Descriptor, Lazy, Allocator>::hash_table (size_t size, bool ggc,
ATTRIBUTE_UNUSED,
mem_alloc_origin origin
MEM_STAT_DECL) :
+#if CHECKING_P
+ m_inserting_slot (0),
+#endif
m_n_elements (0), m_n_deleted (0), m_searches (0), m_collisions (0),
m_ggc (ggc), m_sanitize_eq_and_hash (sanitize_eq_and_hash)
#if GATHER_STATISTICS
@@ -639,6 +672,9 @@ hash_table<Descriptor, Lazy, Allocator>::hash_table (const hash_table &h,
ATTRIBUTE_UNUSED,
mem_alloc_origin origin
MEM_STAT_DECL) :
+#if CHECKING_P
+ m_inserting_slot (0),
+#endif
m_n_elements (h.m_n_elements), m_n_deleted (h.m_n_deleted),
m_searches (0), m_collisions (0), m_ggc (ggc),
m_sanitize_eq_and_hash (sanitize_eq_and_hash)
@@ -646,6 +682,10 @@ hash_table<Descriptor, Lazy, Allocator>::hash_table (const hash_table &h,
, m_gather_mem_stats (gather_mem_stats)
#endif
{
+#if CHECKING_P
+ gcc_checking_assert (!h->check_complete_insertion ());
+#endif
+
size_t size = h.m_size;
if (m_gather_mem_stats)
@@ -675,6 +715,8 @@ template<typename Descriptor, bool Lazy,
template<typename Type> class Allocator>
hash_table<Descriptor, Lazy, Allocator>::~hash_table ()
{
+ check_complete_insertion ();
+
if (!Lazy || m_entries)
{
for (size_t i = m_size - 1; i < m_size; i--)
@@ -778,6 +820,8 @@ template<typename Descriptor, bool Lazy,
void
hash_table<Descriptor, Lazy, Allocator>::expand ()
{
+ check_complete_insertion ();
+
value_type *oentries = m_entries;
unsigned int oindex = m_size_prime_index;
size_t osize = size ();
@@ -853,6 +897,8 @@ template<typename Descriptor, bool Lazy,
void
hash_table<Descriptor, Lazy, Allocator>::empty_slow ()
{
+ check_complete_insertion ();
+
size_t size = m_size;
size_t nsize = size;
value_type *entries = m_entries;
@@ -901,6 +947,8 @@ template<typename Descriptor, bool Lazy,
void
hash_table<Descriptor, Lazy, Allocator>::clear_slot (value_type *slot)
{
+ check_complete_insertion ();
+
gcc_checking_assert (!(slot < m_entries || slot >= m_entries + size ()
|| is_empty (*slot) || is_deleted (*slot)));
@@ -927,6 +975,8 @@ hash_table<Descriptor, Lazy, Allocator>
if (Lazy && m_entries == NULL)
m_entries = alloc_entries (size);
+ check_complete_insertion ();
+
#if CHECKING_P
if (m_sanitize_eq_and_hash)
verify (comparable, hash);
@@ -976,6 +1026,8 @@ hash_table<Descriptor, Lazy, Allocator>
}
if (insert == INSERT && m_size * 3 <= m_n_elements * 4)
expand ();
+ else
+ check_complete_insertion ();
#if CHECKING_P
if (m_sanitize_eq_and_hash)
@@ -1022,11 +1074,11 @@ hash_table<Descriptor, Lazy, Allocator>
{
m_n_deleted--;
mark_empty (*first_deleted_slot);
- return first_deleted_slot;
+ return check_insert_slot (first_deleted_slot);
}
m_n_elements++;
- return &m_entries[index];
+ return check_insert_slot (&m_entries[index]);
}
/* Verify that all existing elements in the hash table which are
@@ -1068,6 +1120,8 @@ void
hash_table<Descriptor, Lazy, Allocator>
::remove_elt_with_hash (const compare_type &comparable, hashval_t hash)
{
+ check_complete_insertion ();
+
value_type *slot = find_slot_with_hash (comparable, hash, NO_INSERT);
if (slot == NULL)
return;
@@ -1094,6 +1148,8 @@ hash_table<Descriptor, Lazy, Allocator>::traverse_noresize (Argument argument)
if (Lazy && m_entries == NULL)
return;
+ check_complete_insertion ();
+
value_type *slot = m_entries;
value_type *limit = slot + size ();
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-12-28 10:28 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-28 6:47 [gcc(refs/users/aoliva/heads/testme)] check hash table insertions Alexandre Oliva
-- strict thread matches above, loose matches on Subject: below --
2022-12-28 10:28 Alexandre Oliva
2022-12-28 8:06 Alexandre Oliva
2022-12-28 6:46 Alexandre Oliva
2022-12-28 6:44 Alexandre Oliva
2022-12-28 5:24 Alexandre Oliva
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).