@@ -149,28 +149,30 @@ 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+ uintptr_t AlignedPtr = 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+ uintptr_t AllocEndPtr = AlignedPtr + SizeToAllocate;
161+ assert (AllocEndPtr >= uintptr_t (CurPtr) &&
162+ " Alignment + Size must not overflow" );
163+
161164 // Check if we have enough space.
162- if (LLVM_LIKELY (Adjustment + SizeToAllocate <= size_t (End - CurPtr )
165+ if (LLVM_LIKELY (AllocEndPtr <= uintptr_t (End)
163166 // We can't return nullptr even for a zero-sized allocation!
164167 && CurPtr != nullptr )) {
165- char *AlignedPtr = CurPtr + Adjustment;
166- CurPtr = AlignedPtr + SizeToAllocate;
168+ CurPtr = reinterpret_cast <char *>(AllocEndPtr);
167169 // Update the allocation point of this memory block in MemorySanitizer.
168170 // Without this, MemorySanitizer messages for values originated from here
169171 // will point to the allocation of the entire slab.
170- __msan_allocated_memory (AlignedPtr, Size);
172+ __msan_allocated_memory (reinterpret_cast < char *>( AlignedPtr) , Size);
171173 // Similarly, tell ASan about this space.
172- __asan_unpoison_memory_region (AlignedPtr, Size);
173- return AlignedPtr;
174+ __asan_unpoison_memory_region (reinterpret_cast < char *>( AlignedPtr) , Size);
175+ return reinterpret_cast < char *>( AlignedPtr) ;
174176 }
175177
176178 return AllocateSlow (Size, SizeToAllocate, Alignment);
0 commit comments