mirror-llvm-project/libc/fuzzing/__support
Schrodinger ZHU Yifan 003ba404c8
[libc] Migrate Block to BlockRef in baremetal allocator (#201001)
Under C++ object lifetime and strict aliasing rules, accessing typed
objects requires that an object of that type actually exists at the
memory location. Previously, the Block structure stored prev and next
offset values, where the prev field overlapped with the usable space of
the preceding block to save space. When the predecessor was allocated,
user payload was written directly to this overlapping space,
complicating object lifetime management. A key issue arose during
reallocation (like in-place shrinking), where the allocator needed to
manipulate block boundaries (e.g., splitting a block) while user payload
was still actively residing in that memory. This caused undefined
behavior due to accessing typed Block members that collided with the
user's active objects.

This patch eliminates the problem by always treating blocks as raw bytes
accessed through a byte-backed proxy (BlockRef). Instead of constructing
or casting to typed Block structures, metadata is read and written using
aligned byte-copy operations (inline_memcpy). This decouples block
manipulation from C++ object lifetime rules, guaranteeing safe access
without violating strict aliasing.

Assisted-by: AI Tools, checked manually
2026-06-09 13:33:04 -07:00
..
CMakeLists.txt [libc][tsearch] add weak AVL tree for tsearch implementation (#172411) 2026-01-21 12:19:34 -05:00
freelist_heap_fuzz.cpp [libc] Migrate Block to BlockRef in baremetal allocator (#201001) 2026-06-09 13:33:04 -07:00
hashtable_fuzz.cpp
uint_fuzz.cpp
weak_avl_fuzz.cpp [libc][tsearch] add weak AVL tree for tsearch implementation (#172411) 2026-01-21 12:19:34 -05:00