diff options
author | Evan Brown <ezb@google.com> | 2022-12-19 11:53:21 -0800 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2022-12-19 11:54:08 -0800 |
commit | a1ec5d62e70994d4d488d827f4e44a9a4165fd36 (patch) | |
tree | 1c8e0e5b8d8a351f50005da33254a6531b98882e /absl/container/internal/raw_hash_set.cc | |
parent | dbc61b490c5c259df33af59f9922a7224341397b (diff) | |
download | abseil-a1ec5d62e70994d4d488d827f4e44a9a4165fd36.tar.gz abseil-a1ec5d62e70994d4d488d827f4e44a9a4165fd36.tar.bz2 abseil-a1ec5d62e70994d4d488d827f4e44a9a4165fd36.zip |
In sanitizer mode, add generations to swisstable iterators and backing arrays so that we can detect invalid iterator use.
PiperOrigin-RevId: 496455788
Change-Id: I83df92828098a3ef1181b4e454f3ac5d3ac7a2f2
Diffstat (limited to 'absl/container/internal/raw_hash_set.cc')
-rw-r--r-- | absl/container/internal/raw_hash_set.cc | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/absl/container/internal/raw_hash_set.cc b/absl/container/internal/raw_hash_set.cc index 79220836..3677ac59 100644 --- a/absl/container/internal/raw_hash_set.cc +++ b/absl/container/internal/raw_hash_set.cc @@ -26,11 +26,14 @@ namespace container_internal { // A single block of empty control bytes for tables without any slots allocated. // This enables removing a branch in the hot path of find(). -alignas(16) ABSL_CONST_INIT ABSL_DLL const ctrl_t kEmptyGroup[16] = { +// We have 17 bytes because there may be a generation counter. Any constant is +// fine for the generation counter. +alignas(16) ABSL_CONST_INIT ABSL_DLL const ctrl_t kEmptyGroup[17] = { ctrl_t::kSentinel, ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty, - ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty}; + ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty, + static_cast<ctrl_t>(0)}; #ifdef ABSL_INTERNAL_NEED_REDUNDANT_CONSTEXPR_DECL constexpr size_t Group::kWidth; @@ -190,24 +193,24 @@ void EraseMetaOnly(CommonFields& c, ctrl_t* it, size_t slot_size) { SetCtrl(c, index, was_never_full ? ctrl_t::kEmpty : ctrl_t::kDeleted, slot_size); - c.growth_left_ += (was_never_full ? 1 : 0); + c.growth_left() += (was_never_full ? 1 : 0); c.infoz().RecordErase(); } void ClearBackingArray(CommonFields& c, const PolicyFunctions& policy, bool reuse) { + c.size_ = 0; if (reuse) { - c.size_ = 0; ResetCtrl(c, policy.slot_size); c.infoz().RecordStorageChanged(0, c.capacity_); } else { void* set = &c; (*policy.dealloc)(set, policy, c.control_, c.slots_, c.capacity_); c.control_ = EmptyGroup(); + c.set_generation_ptr(EmptyGeneration()); c.slots_ = nullptr; - c.size_ = 0; c.capacity_ = 0; - c.growth_left_ = 0; + c.growth_left() = 0; c.infoz().RecordClearedReservation(); assert(c.size_ == 0); c.infoz().RecordStorageChanged(0, 0); |