Skip to content

Commit 7184114

Browse files
committed
Fix asan/TestCases/Darwin/scrible.cpp to work on platforms where long is not 64-bits.
Previously the test was failing on platforms where `long` was less than 64-bits wide (e.g. older WatchOS simulators and arm64_32) because the `padding` field was too small. The test currently relies on the `my_object->isa` being scribbled or left unmodified after `my_object` is freed. However, this was not the case because the `isa` pointer intersected with `ChunkHeader::free_context_id`. `free_context_id` starts at the beginning of user memory but it only initialized once the memory is freed. This caused the `isa` pointer to change after it was freed leading to the test crashing. To fix this the `padding` field has been made explicitly 64-bits wide (same size as `ChunkHeader::free_context_id`). rdar://75806757 Differential Revision: https://reviews.llvm.org/D109409
1 parent f428625 commit 7184114

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

compiler-rt/test/asan/TestCases/Darwin/scribble.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,14 @@ struct Isa {
1313
};
1414

1515
struct MyClass {
16-
long padding;
16+
// User memory and `ChunkHeader` overlap. In particular the `free_context_id`
17+
// is stored at the beginning of user memory when it is freed. That part of
18+
// user memory is not scribbled and is changed when the memory is freed. This
19+
// test relies on `isa` being scribbled or unmodified after memory is freed.
20+
// In order for this to work the start of `isa` must come after whatever is in
21+
// `ChunkHeader` (currently the 64-bit `free_context_id`). The padding here is
22+
// to ensure this is the case.
23+
uint64_t padding;
1724
Isa *isa;
1825
long data;
1926

0 commit comments

Comments
 (0)