Skip to content

Commit 186d4f6

Browse files
committed
Simplify hot-path size computations in BumpPtrAllocator.
1 parent 07d2709 commit 186d4f6

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

llvm/include/llvm/Support/Allocator.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,21 +149,21 @@ class BumpPtrAllocatorImpl
149149
// Keep track of how many bytes we've allocated.
150150
BytesAllocated += Size;
151151

152-
size_t Adjustment = offsetToAlignedAddr(CurPtr, Alignment);
153-
assert(Adjustment + Size >= Size && "Adjustment + Size must not overflow");
152+
char *AlignedPtr = reinterpret_cast<char *>(alignAddr(CurPtr, Alignment));
154153

155154
size_t SizeToAllocate = Size;
156155
#if LLVM_ADDRESS_SANITIZER_BUILD
157156
// Add trailing bytes as a "red zone" under ASan.
158157
SizeToAllocate += RedZoneSize;
159158
#endif
160159

160+
char *AllocEndPtr = AlignedPtr + SizeToAllocate;
161+
161162
// Check if we have enough space.
162-
if (LLVM_LIKELY(Adjustment + SizeToAllocate <= size_t(End - CurPtr)
163+
if (LLVM_LIKELY(AllocEndPtr <= End
163164
// We can't return nullptr even for a zero-sized allocation!
164165
&& CurPtr != nullptr)) {
165-
char *AlignedPtr = CurPtr + Adjustment;
166-
CurPtr = AlignedPtr + SizeToAllocate;
166+
CurPtr = AllocEndPtr;
167167
// Update the allocation point of this memory block in MemorySanitizer.
168168
// Without this, MemorySanitizer messages for values originated from here
169169
// will point to the allocation of the entire slab.

0 commit comments

Comments
 (0)