[Support] Fix UB in BumpPtrAllocator when first allocation is zero.
BumpPtrAllocator::Allocate() is marked __attribute__((returns_nonnull)) when the compiler supports it, which makes it UB to return null. When there have been no allocations yet, the current slab is [nullptr, nullptr). A zero-sized allocation fits in this range, and so Allocate(0, 1) returns null. There's no explicit docs whether Allocate(0) is valid. I think we have to assume that it is: - the implementation tries to support it (e.g. >= tests instead of >) - malloc(0) is allowed - requiring each callsite to do a check is bug-prone - I found real LLVM code that makes zero-sized allocations Differential Revision: https://reviews.llvm.org/D125040
Loading
Please sign in to comment