diff --git a/llvm/include/llvm/Support/Allocator.h b/llvm/include/llvm/Support/Allocator.h index c1e5c6d2853bd..eb6c4d3668550 100644 --- a/llvm/include/llvm/Support/Allocator.h +++ b/llvm/include/llvm/Support/Allocator.h @@ -159,9 +159,9 @@ class BumpPtrAllocatorImpl #endif // Check if we have enough space. - if (Adjustment + SizeToAllocate <= size_t(End - CurPtr) - // We can't return nullptr even for a zero-sized allocation! - && CurPtr != nullptr) { + if (LLVM_LIKELY(Adjustment + SizeToAllocate <= size_t(End - CurPtr) + // We can't return nullptr even for a zero-sized allocation! + && CurPtr != nullptr)) { char *AlignedPtr = CurPtr + Adjustment; CurPtr = AlignedPtr + SizeToAllocate; // Update the allocation point of this memory block in MemorySanitizer. @@ -173,6 +173,11 @@ class BumpPtrAllocatorImpl return AlignedPtr; } + return AllocateSlow(Size, SizeToAllocate, Alignment); + } + + LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_NOINLINE void * + AllocateSlow(size_t Size, size_t SizeToAllocate, Align Alignment) { // If Size is really big, allocate a separate slab for it. size_t PaddedSize = SizeToAllocate + Alignment.value() - 1; if (PaddedSize > SizeThreshold) {