[llvm] [Allocator] Keep bump pointer at a minimum alignment (PR #203718)
Alexis Engelke via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 14 03:55:34 PDT 2026
================
@@ -150,30 +161,31 @@ class BumpPtrAllocatorImpl
// Keep track of how many bytes we've allocated.
BytesAllocated += Size;
- uintptr_t AlignedPtr = alignAddr(CurPtr, Alignment);
-
size_t SizeToAllocate = Size;
#if LLVM_ADDRESS_SANITIZER_BUILD
// Add trailing bytes as a "red zone" under ASan.
SizeToAllocate += RedZoneSize;
#endif
+ SizeToAllocate = alignToPowerOf2(SizeToAllocate, MinAlign);
- uintptr_t AllocEndPtr = AlignedPtr + SizeToAllocate;
- assert(AllocEndPtr >= uintptr_t(CurPtr) &&
+ // CurPtr is already MinAlign-aligned, so only a stricter request realigns.
+ char *Ptr = CurPtr;
+ if (Alignment.value() > MinAlign)
+ Ptr = reinterpret_cast<char *>(alignAddr(Ptr, Alignment));
----------------
aengelke wrote:
I'm wondering whether we get optimization improvements when using __builtin_align_up with Clang and avoid all pointer-to-int casts. That would avoid exposing the provenance and could help alias analysis -- not sure if there's a practical effect, though.
https://github.com/llvm/llvm-project/pull/203718
More information about the llvm-commits
mailing list