[llvm] 67730ae - Revert "Simplify hot-path size computations in BumpPtrAllocator. (#101312)"
Owen Anderson via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 1 03:09:11 PDT 2024
Author: Owen Anderson
Date: 2024-08-01T00:08:53-10:00
New Revision: 67730ae19c6bcb08dca292e0576b6cd55a843932
URL: https://github.com/llvm/llvm-project/commit/67730ae19c6bcb08dca292e0576b6cd55a843932
DIFF: https://github.com/llvm/llvm-project/commit/67730ae19c6bcb08dca292e0576b6cd55a843932.diff
LOG: Revert "Simplify hot-path size computations in BumpPtrAllocator. (#101312)"
This reverts commit 65c000a1e5a2a1c79eb5e022c3dc51b239691153.
Added:
Modified:
llvm/include/llvm/Support/Allocator.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/Support/Allocator.h b/llvm/include/llvm/Support/Allocator.h
index 6be7c320a26f8..e05f0ec0e8704 100644
--- a/llvm/include/llvm/Support/Allocator.h
+++ b/llvm/include/llvm/Support/Allocator.h
@@ -149,7 +149,8 @@ class BumpPtrAllocatorImpl
// Keep track of how many bytes we've allocated.
BytesAllocated += Size;
- uintptr_t AlignedPtr = alignAddr(CurPtr, Alignment);
+ size_t Adjustment = offsetToAlignedAddr(CurPtr, Alignment);
+ assert(Adjustment + Size >= Size && "Adjustment + Size must not overflow");
size_t SizeToAllocate = Size;
#if LLVM_ADDRESS_SANITIZER_BUILD
@@ -157,22 +158,19 @@ class BumpPtrAllocatorImpl
SizeToAllocate += RedZoneSize;
#endif
- uintptr_t AllocEndPtr = AlignedPtr + SizeToAllocate;
- assert(AllocEndPtr >= uintptr_t(CurPtr) &&
- "Alignment + Size must not overflow");
-
// Check if we have enough space.
- if (LLVM_LIKELY(AllocEndPtr <= uintptr_t(End)
+ if (LLVM_LIKELY(Adjustment + SizeToAllocate <= size_t(End - CurPtr)
// We can't return nullptr even for a zero-sized allocation!
&& CurPtr != nullptr)) {
- CurPtr = reinterpret_cast<char *>(AllocEndPtr);
+ char *AlignedPtr = CurPtr + Adjustment;
+ CurPtr = AlignedPtr + SizeToAllocate;
// Update the allocation point of this memory block in MemorySanitizer.
// Without this, MemorySanitizer messages for values originated from here
// will point to the allocation of the entire slab.
__msan_allocated_memory(AlignedPtr, Size);
// Similarly, tell ASan about this space.
__asan_unpoison_memory_region(AlignedPtr, Size);
- return reinterpret_cast<char *>(AlignedPtr);
+ return AlignedPtr;
}
return AllocateSlow(Size, SizeToAllocate, Alignment);
More information about the llvm-commits
mailing list