From 7676c565eedd2581b66839c239f3825d8e381119 Mon Sep 17 00:00:00 2001 From: Evan Brown Date: Tue, 17 Oct 2023 12:30:58 -0700 Subject: Rollback: Add sanitizer mode checks that element constructors/destructors don't make reentrant calls to raw_hash_set member functions. PiperOrigin-RevId: 574232718 Change-Id: I8ef25fec00b76ee5fb9424e7614ca55edd6ba81b --- absl/container/internal/raw_hash_set_test.cc | 84 ++++------------------------ 1 file changed, 10 insertions(+), 74 deletions(-) (limited to 'absl/container/internal/raw_hash_set_test.cc') diff --git a/absl/container/internal/raw_hash_set_test.cc b/absl/container/internal/raw_hash_set_test.cc index 4e67b79e..d194ca1b 100644 --- a/absl/container/internal/raw_hash_set_test.cc +++ b/absl/container/internal/raw_hash_set_test.cc @@ -49,10 +49,8 @@ #include "absl/container/internal/hash_policy_testing.h" #include "absl/container/internal/hashtable_debug.h" #include "absl/container/internal/test_allocator.h" -#include "absl/functional/function_ref.h" #include "absl/log/log.h" #include "absl/strings/string_view.h" -#include "absl/types/optional.h" namespace absl { ABSL_NAMESPACE_BEGIN @@ -411,15 +409,19 @@ struct StringTable using Base::Base; }; -template -struct ValueTable : raw_hash_set, hash_default_hash, - std::equal_to, std::allocator> { - using Base = typename ValueTable::raw_hash_set; +struct IntTable + : raw_hash_set, + std::equal_to, std::allocator> { + using Base = typename IntTable::raw_hash_set; using Base::Base; }; -using IntTable = ValueTable; -using Uint8Table = ValueTable; +struct Uint8Table + : raw_hash_set, + std::equal_to, std::allocator> { + using Base = typename Uint8Table::raw_hash_set; + using Base::Base; +}; template struct CustomAlloc : std::allocator { @@ -2487,72 +2489,6 @@ using RawHashSetAlloc = raw_hash_set, TEST(Table, AllocatorPropagation) { TestAllocPropagation(); } -struct ConstructCaller { - explicit ConstructCaller(int v) : val(v) {} - ConstructCaller(int v, absl::FunctionRef func) : val(v) { func(); } - template - friend H AbslHashValue(H h, const ConstructCaller& d) { - return H::combine(std::move(h), d.val); - } - bool operator==(const ConstructCaller& c) const { return val == c.val; } - - int val; -}; - -struct DestroyCaller { - explicit DestroyCaller(int v) : val(v) {} - DestroyCaller(int v, absl::FunctionRef func) - : val(v), destroy_func(func) {} - DestroyCaller(DestroyCaller&& that) - : val(that.val), destroy_func(std::move(that.destroy_func)) { - that.Deactivate(); - } - ~DestroyCaller() { - if (destroy_func) (*destroy_func)(); - } - void Deactivate() { destroy_func = absl::nullopt; } - - template - friend H AbslHashValue(H h, const DestroyCaller& d) { - return H::combine(std::move(h), d.val); - } - bool operator==(const DestroyCaller& d) const { return val == d.val; } - - int val; - absl::optional> destroy_func; -}; - -#if defined(ABSL_HAVE_ADDRESS_SANITIZER) || defined(ABSL_HAVE_MEMORY_SANITIZER) -TEST(Table, ReentrantCallsFail) { - constexpr const char* kDeathMessage = - "use-after-poison|use-of-uninitialized-value"; - { - ValueTable t; - t.insert(ConstructCaller{0}); - auto erase_begin = [&] { t.erase(t.begin()); }; - EXPECT_DEATH_IF_SUPPORTED(t.emplace(1, erase_begin), kDeathMessage); - } - { - ValueTable t; - t.insert(DestroyCaller{0}); - auto find_0 = [&] { t.find(DestroyCaller{0}); }; - t.insert(DestroyCaller{1, find_0}); - for (int i = 10; i < 20; ++i) t.insert(DestroyCaller{i}); - EXPECT_DEATH_IF_SUPPORTED(t.clear(), kDeathMessage); - for (auto& elem : t) elem.Deactivate(); - } - { - ValueTable t; - t.insert(DestroyCaller{0}); - auto insert_1 = [&] { t.insert(DestroyCaller{1}); }; - t.insert(DestroyCaller{1, insert_1}); - for (int i = 10; i < 20; ++i) t.insert(DestroyCaller{i}); - EXPECT_DEATH_IF_SUPPORTED(t.clear(), kDeathMessage); - for (auto& elem : t) elem.Deactivate(); - } -} -#endif - } // namespace } // namespace container_internal ABSL_NAMESPACE_END -- cgit v1.2.3