[llvm] Simplify hot-path size computations in BumpPtrAllocator. (PR #101312)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 31 06:31:48 PDT 2024
================
@@ -149,21 +149,21 @@ class BumpPtrAllocatorImpl
// Keep track of how many bytes we've allocated.
BytesAllocated += Size;
- size_t Adjustment = offsetToAlignedAddr(CurPtr, Alignment);
- assert(Adjustment + Size >= Size && "Adjustment + Size must not overflow");
+ char *AlignedPtr = reinterpret_cast<char *>(alignAddr(CurPtr, Alignment));
----------------
nikic wrote:
We should keep this as an integer, otherwise the addition below may be UB.
The current code was introduced in https://github.com/llvm/llvm-project/commit/44e27464181168faa2b2c4a6e92797ab96215cac by @zmodem. I think it's fine to essentially undo that change, but you should add an explicit check that the AlignedPtr + Size addition does not overflow.
https://github.com/llvm/llvm-project/pull/101312
More information about the llvm-commits
mailing list