Skip to content

Commit 3acbe29

Browse files
Abseil Teamcopybara-github
authored andcommitted
Enable ABSL_BTREE_ENABLE_GENERATIONS and ABSL_SWISSTABLE_ENABLE_GENERATIONS with ABSL_HAVE_HWADDRESS_SANITIZER.
It will detect bugs similar to Asan. Also updated related tests to pass with HWASAN. They are still flaky because of nature of HWASAN algorithm, but test can be update to avoid flakiness, which I will do in followup patches. PiperOrigin-RevId: 597613798 Change-Id: Ic8af36a268ca041c002eb561b946aa2d9b93996a
1 parent a00f6d6 commit 3acbe29

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

absl/container/btree_test.cc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,8 @@ void ExpectOperationCounts(const int expected_moves,
13461346
tracker->ResetCopiesMovesSwaps();
13471347
}
13481348

1349-
#ifdef ABSL_HAVE_ADDRESS_SANITIZER
1349+
#if defined(ABSL_HAVE_ADDRESS_SANITIZER) || \
1350+
defined(ABSL_HAVE_HWADDRESS_SANITIZER)
13501351
constexpr bool kAsan = true;
13511352
#else
13521353
constexpr bool kAsan = false;
@@ -3079,10 +3080,10 @@ TEST(Btree, InvalidIteratorUse) {
30793080
if (!BtreeGenerationsEnabled())
30803081
GTEST_SKIP() << "Generation validation for iterators is disabled.";
30813082

3082-
// Invalid memory use can trigger heap-use-after-free in ASan or invalidated
3083-
// iterator assertions.
3083+
// Invalid memory use can trigger use-after-free in ASan, HWASAN or
3084+
// invalidated iterator assertions.
30843085
constexpr const char *kInvalidMemoryDeathMessage =
3085-
"heap-use-after-free|invalidated iterator";
3086+
"use-after-free|invalidated iterator";
30863087

30873088
{
30883089
absl::btree_set<int> set;
@@ -3411,12 +3412,12 @@ TEST(Btree, InvalidPointerUse) {
34113412
set.insert(0);
34123413
const int *ptr = &*set.begin();
34133414
set.insert(1);
3414-
EXPECT_DEATH(std::cout << *ptr, "heap-use-after-free");
3415+
EXPECT_DEATH(std::cout << *ptr, "use-after-free");
34153416
size_t slots_per_node = BtreeNodePeer::GetNumSlotsPerNode<decltype(set)>();
34163417
for (int i = 2; i < slots_per_node - 1; ++i) set.insert(i);
34173418
ptr = &*set.begin();
34183419
set.insert(static_cast<int>(slots_per_node));
3419-
EXPECT_DEATH(std::cout << *ptr, "heap-use-after-free");
3420+
EXPECT_DEATH(std::cout << *ptr, "use-after-free");
34203421
}
34213422

34223423
template<typename Set>

absl/container/internal/btree.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ namespace container_internal {
7979
#ifdef ABSL_BTREE_ENABLE_GENERATIONS
8080
#error ABSL_BTREE_ENABLE_GENERATIONS cannot be directly set
8181
#elif defined(ABSL_HAVE_ADDRESS_SANITIZER) || \
82+
defined(ABSL_HAVE_HWADDRESS_SANITIZER) || \
8283
defined(ABSL_HAVE_MEMORY_SANITIZER)
8384
// When compiled in sanitizer mode, we add generation integers to the nodes and
8485
// iterators. When iterators are used, we validate that the container has not
@@ -2856,7 +2857,8 @@ inline auto btree<P>::internal_emplace(iterator iter, Args &&...args)
28562857
}
28572858
}
28582859
(void)replaced_node;
2859-
#ifdef ABSL_HAVE_ADDRESS_SANITIZER
2860+
#if defined(ABSL_HAVE_ADDRESS_SANITIZER) || \
2861+
defined(ABSL_HAVE_HWADDRESS_SANITIZER)
28602862
if (!replaced_node) {
28612863
assert(iter.node_->is_leaf());
28622864
if (iter.node_->is_root()) {

absl/container/internal/raw_hash_set.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ namespace container_internal {
234234
#ifdef ABSL_SWISSTABLE_ENABLE_GENERATIONS
235235
#error ABSL_SWISSTABLE_ENABLE_GENERATIONS cannot be directly set
236236
#elif defined(ABSL_HAVE_ADDRESS_SANITIZER) || \
237+
defined(ABSL_HAVE_HWADDRESS_SANITIZER) || \
237238
defined(ABSL_HAVE_MEMORY_SANITIZER)
238239
// When compiled in sanitizer mode, we add generation integers to the backing
239240
// array and iterators. In the backing array, we store the generation between

absl/container/internal/raw_hash_set_test.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2218,10 +2218,10 @@ TEST(TableDeathTest, InvalidIteratorAsserts) {
22182218
EXPECT_DEATH_IF_SUPPORTED(++iter, kErasedDeathMessage);
22192219
}
22202220

2221-
// Invalid iterator use can trigger heap-use-after-free in asan,
2221+
// Invalid iterator use can trigger use-after-free in asan/hwasan,
22222222
// use-of-uninitialized-value in msan, or invalidated iterator assertions.
22232223
constexpr const char* kInvalidIteratorDeathMessage =
2224-
"heap-use-after-free|use-of-uninitialized-value|invalidated "
2224+
"use-after-free|use-of-uninitialized-value|invalidated "
22252225
"iterator|Invalid iterator|invalid iterator";
22262226

22272227
// MSVC doesn't support | in regex.
@@ -2579,7 +2579,7 @@ TEST(Table, InvalidReferenceUseCrashesWithSanitizers) {
25792579
// ptr will become invalidated on rehash.
25802580
const int64_t* ptr = &*t.begin();
25812581
t.insert(++i);
2582-
EXPECT_DEATH_IF_SUPPORTED(std::cout << *ptr, "heap-use-after-free") << i;
2582+
EXPECT_DEATH_IF_SUPPORTED(std::cout << *ptr, "use-after-free") << i;
25832583
}
25842584
}
25852585

0 commit comments

Comments
 (0)