public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/aoliva/heads/testme)] hash table: enforce testing is_empty before is_deleted
@ 2023-01-12 4:03 Alexandre Oliva
0 siblings, 0 replies; only message in thread
From: Alexandre Oliva @ 2023-01-12 4:03 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:c4776d8d10f14df1089a5fe1bc73f9268c3c8e85
commit c4776d8d10f14df1089a5fe1bc73f9268c3c8e85
Author: Alexandre Oliva <oliva@gnu.org>
Date: Thu Jan 12 01:01:53 2023 -0300
hash table: enforce testing is_empty before is_deleted
Diff:
---
gcc/hash-table.h | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/gcc/hash-table.h b/gcc/hash-table.h
index 1d3166504c3..e37625dc315 100644
--- a/gcc/hash-table.h
+++ b/gcc/hash-table.h
@@ -534,6 +534,11 @@ private:
void expand ();
static bool is_deleted (value_type &v)
{
+ /* Traits are supposed to avoid recognizing elements as both empty
+ and deleted, but to fail safe in case custom traits fail to do
+ that, make sure we never test for is_deleted without having
+ first ruled out is_empty. */
+ gcc_checking_assert (!Descriptor::is_empty (v));
return Descriptor::is_deleted (v);
}
@@ -545,6 +550,11 @@ private:
static void mark_deleted (value_type &v)
{
Descriptor::mark_deleted (v);
+ /* Traits are supposed to refuse to set elements as deleted if
+ those would be indistinguishable from empty, but to fail safe
+ in case custom traits fail to do that, check that the
+ just-deleted element does not look empty. */
+ gcc_checking_assert (!Descriptor::is_empty (v));
}
static void mark_empty (value_type &v)
@@ -700,9 +710,11 @@ hash_table<Descriptor, Lazy, Allocator>::hash_table (const hash_table &h,
for (size_t i = 0; i < size; ++i)
{
value_type &entry = h.m_entries[i];
- if (is_deleted (entry))
+ if (is_empty (entry))
+ continue;
+ else if (is_deleted (entry))
mark_deleted (nentries[i]);
- else if (!is_empty (entry))
+ else
new ((void*) (nentries + i)) value_type (entry);
}
m_entries = nentries;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-01-12 4:03 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-12 4:03 [gcc(refs/users/aoliva/heads/testme)] hash table: enforce testing is_empty before is_deleted 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).