diff options
author | Evan Brown <ezb@google.com> | 2023-01-30 14:59:39 -0800 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-01-30 15:01:00 -0800 |
commit | ed59f62f8bbc5f05bcba2f89ee16f107e03813f2 (patch) | |
tree | 3d4a917a7a988580a3a5cbb024e9f08b5c02b0e8 /absl/container/internal/raw_hash_set_test.cc | |
parent | 0c3df2f5a7d3918b9e5762cd8f143a6004b76cda (diff) | |
download | abseil-ed59f62f8bbc5f05bcba2f89ee16f107e03813f2.tar.gz abseil-ed59f62f8bbc5f05bcba2f89ee16f107e03813f2.tar.bz2 abseil-ed59f62f8bbc5f05bcba2f89ee16f107e03813f2.zip |
In sanitizer mode, detect when references become invalidated by randomly rehashing on insertions when there is no reserved growth.
PiperOrigin-RevId: 505807487
Change-Id: I9051a04f6a75e579d16e9ae8defd404bcc377fba
Diffstat (limited to 'absl/container/internal/raw_hash_set_test.cc')
-rw-r--r-- | absl/container/internal/raw_hash_set_test.cc | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/absl/container/internal/raw_hash_set_test.cc b/absl/container/internal/raw_hash_set_test.cc index bdffb817..e33fda20 100644 --- a/absl/container/internal/raw_hash_set_test.cc +++ b/absl/container/internal/raw_hash_set_test.cc @@ -865,6 +865,10 @@ void TestDecompose(bool construct_three) { } TEST(Table, Decompose) { + if (SwisstableGenerationsEnabled()) { + GTEST_SKIP() << "Generations being enabled causes extra rehashes."; + } + TestDecompose<DecomposeHash, DecomposeEq>(false); struct TransparentHashIntOverload { @@ -903,6 +907,10 @@ struct Modulo1000HashTable // Test that rehash with no resize happen in case of many deleted slots. TEST(Table, RehashWithNoResize) { + if (SwisstableGenerationsEnabled()) { + GTEST_SKIP() << "Generations being enabled causes extra rehashes."; + } + Modulo1000HashTable t; // Adding the same length (and the same hash) strings // to have at least kMinFullGroups groups @@ -996,6 +1004,10 @@ TEST(Table, EnsureNonQuadraticAsInRust) { } TEST(Table, ClearBug) { + if (SwisstableGenerationsEnabled()) { + GTEST_SKIP() << "Generations being enabled causes extra rehashes."; + } + IntTable t; constexpr size_t capacity = container_internal::Group::kWidth - 1; constexpr size_t max_size = capacity / 2 + 1; @@ -2318,6 +2330,25 @@ TEST(Table, ReservedGrowthUpdatesWhenTableDoesntGrow) { EXPECT_EQ(*it, 0); } +TEST(Table, InvalidReferenceUseCrashesWithSanitizers) { + if (!SwisstableGenerationsEnabled()) GTEST_SKIP() << "Generations disabled."; +#ifdef ABSL_HAVE_MEMORY_SANITIZER + GTEST_SKIP() << "MSan fails to detect some of these rehashes."; +#endif + + IntTable t; + t.insert(0); + // Rehashing is guaranteed on every insertion while capacity is less than + // RehashProbabilityConstant(). + int64_t i = 0; + while (t.capacity() <= RehashProbabilityConstant()) { + // ptr will become invalidated on rehash. + const int64_t* ptr = &*t.begin(); + t.insert(++i); + EXPECT_DEATH_IF_SUPPORTED(std::cout << *ptr, "heap-use-after-free") << i; + } +} + } // namespace } // namespace container_internal ABSL_NAMESPACE_END |