Skip to content

Truly independent web browser

Tests/LibGC: Run each TestGCHeapGroup case on freshly scrubbed stack

sideshowbarker8a562109797d
diff --git a/Tests/LibGC/TestGCHeapGroup.cpp b/Tests/LibGC/TestGCHeapGroup.cpp
index 13bf65823a9..b3faae26c6c 100644
--- a/Tests/LibGC/TestGCHeapGroup.cpp
+++ b/Tests/LibGC/TestGCHeapGroup.cpp
@@ -43,7 +43,9 @@ private:
GC_DEFINE_ALLOCATOR(LinkedCell);
-NEVER_INLINE void scrub_stack()
+// Under ASan, an instrumented function's locals live on a fake stack, so filling them would leave the real stack as it
+// was — and the conservative scan reads the real stack. So this function isn't instrumented.
+NO_SANITIZE_ADDRESS NEVER_INLINE void scrub_stack()
{
u8 volatile filler[8 * KiB];
for (size_t i = 0; i < sizeof(filler); ++i)
@@ -84,7 +86,7 @@ NEVER_INLINE void allocate_garbage(GC::Heap& heap)
}
-TEST_CASE(sanity_single_heap_frees_garbage)
+static NEVER_INLINE void sanity_single_heap_frees_garbage()
{
GC::Heap heap([](auto&) { }, GC::Heap::BecomeProcessDefault::No);
heap.set_incremental_sweep_enabled(false);
@@ -96,7 +98,7 @@ TEST_CASE(sanity_single_heap_frees_garbage)
EXPECT_EQ(s_live_linked_cells, 0u);
}
-TEST_CASE(incoming_cross_heap_member_roots_local_collection)
+static NEVER_INLINE void incoming_cross_heap_member_roots_local_collection()
{
GC::Heap heap_a([](auto&) { }, GC::Heap::BecomeProcessDefault::No);
GC::Heap heap_b([](auto&) { }, GC::Heap::BecomeProcessDefault::No);
@@ -130,7 +132,7 @@ TEST_CASE(incoming_cross_heap_member_roots_local_collection)
group.remove(heap_b);
}
-TEST_CASE(group_collection_breaks_cross_heap_cycles)
+static NEVER_INLINE void group_collection_breaks_cross_heap_cycles()
{
GC::Heap heap_a([](auto&) { }, GC::Heap::BecomeProcessDefault::No);
GC::Heap heap_b([](auto&) { }, GC::Heap::BecomeProcessDefault::No);
@@ -159,7 +161,7 @@ TEST_CASE(group_collection_breaks_cross_heap_cycles)
group.remove(heap_b);
}
-TEST_CASE(group_collection_traces_live_cross_heap_chains)
+static NEVER_INLINE void group_collection_traces_live_cross_heap_chains()
{
GC::Heap heap_a([](auto&) { }, GC::Heap::BecomeProcessDefault::No);
GC::Heap heap_b([](auto&) { }, GC::Heap::BecomeProcessDefault::No);
@@ -186,3 +188,31 @@ TEST_CASE(group_collection_traces_live_cross_heap_chains)
group.remove(heap_a);
group.remove(heap_b);
}
+
+// Under ASan with detect_stack_use_after_return, a function's locals live on a fake stack, but its frame on the real
+// stack still reserves room for them — room it never writes, so it keeps whatever earlier calls left there, and the
+// conservative scan reads it. A stale pointer there can keep a dropped cell alive. So each case runs in a frame of its
+// own, on stack that scrub_stack() has just cleared.
+TEST_CASE(sanity_single_heap_frees_garbage)
+{
+ scrub_stack();
+ sanity_single_heap_frees_garbage();
+}
+
+TEST_CASE(incoming_cross_heap_member_roots_local_collection)
+{
+ scrub_stack();
+ incoming_cross_heap_member_roots_local_collection();
+}
+
+TEST_CASE(group_collection_breaks_cross_heap_cycles)
+{
+ scrub_stack();
+ group_collection_breaks_cross_heap_cycles();
+}
+
+TEST_CASE(group_collection_traces_live_cross_heap_chains)
+{
+ scrub_stack();
+ group_collection_traces_live_cross_heap_chains();
+}