Deflake raw_hash_set_test under HWASan and hashtablez sampling. In Table.InvalidReferenceUseCrashesWithSanitizers, move the pointer capture and rehash-triggering insertion inside the EXPECT_DEATH_IF_SUPPORTED statement block. Previously, t.insert(++i) freed the old backing array before EXPECT_DEATH_IF_SUPPORTED set up its death-test matcher and runner objects; under HWASan (which has no quarantine and 6-bit random pointer tags), those GoogleTest allocations could reuse the just-freed backing array from the LIFO freelist and collide with the old pointer's 6-bit tag with probability 1/64, causing the dereference not to crash. Also call DisableSampling() in ExtendedSooTest.ReserveTwice, SooTest.RehashZeroForSmallTable, SooTest.RangeConstructorReservation, and SooTest.IteratorInvalidAssertsEqualityOperator, which assume 1-element SOO tables remain in SOO mode rather than being sampled onto the heap. PiperOrigin-RevId: 1010654606
diff --git a/absl/container/internal/raw_hash_set_test.cc b/absl/container/internal/raw_hash_set_test.cc index 4c33b4f..91fb65f 100644 --- a/absl/container/internal/raw_hash_set_test.cc +++ b/absl/container/internal/raw_hash_set_test.cc
@@ -1801,6 +1801,9 @@ } TYPED_TEST(ExtendedSooTest, ReserveTwice) { + // We need to disable hashtablez to avoid issues related to SOO and sampling. + DisableSampling(); + for (int reserve_size = 0; reserve_size < 32; ++reserve_size) { for (int reserve_size2 = reserve_size; reserve_size2 < 32; ++reserve_size2) { @@ -2358,6 +2361,9 @@ } TYPED_TEST(SooTest, RehashZeroForSmallTable) { + // We need to disable hashtablez to avoid issues related to SOO and sampling. + DisableSampling(); + TypeParam t{0}; EXPECT_EQ(t.capacity(), 1); t.rehash(0); @@ -2370,6 +2376,9 @@ } TYPED_TEST(SooTest, RangeConstructorReservation) { + // We need to disable hashtablez to avoid issues related to SOO and sampling. + DisableSampling(); + constexpr int kMaxSize = 25; std::vector<int> v; for (int size = 1; size <= kMaxSize; ++size) { @@ -2522,6 +2531,9 @@ if (!IsAssertEnabled() && !SwisstableGenerationsEnabled()) GTEST_SKIP() << "Assertions not enabled."; + // We need to disable hashtablez to avoid issues related to SOO and sampling. + DisableSampling(); + TypeParam t; t.insert(1); t.insert(2); @@ -4805,10 +4817,17 @@ // RehashProbabilityConstant(). int i = 0; while (t.capacity() <= RehashProbabilityConstant()) { - // ptr will become invalidated on rehash. - const auto* ptr = &*t.begin(); - t.insert(++i); - EXPECT_DEATH_IF_SUPPORTED(std::cout << **ptr, "use-after-free") << i; + ++i; + EXPECT_DEATH_IF_SUPPORTED( + { + // ptr will become invalidated on rehash. + const auto* ptr = &*t.begin(); + t.insert(i); + std::cout << **ptr; + }, + "use-after-free") + << i; + t.insert(i); } }