[PATCH] D51317: Handle BumpPtrAllocator::Allocate(0) without undefined behavior
Hans Wennborg via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 31 02:16:50 PDT 2018
hans added a comment.
In https://reviews.llvm.org/D51317#1220484, @brentdax wrote:
> I think the best solution is to make BumpPtrAllocator::Allocate() consistently return nullptr for zero-size allocations.
> Zero-size allocations are already extremely common in the wild; allocating space unnecessarily just imposes a softer
> requirement for users to avoid doing it; a guard page is massive overkill; the noalias guarantee seems more valuable;
> and users already had to be prepared to occasionally receive nullptr returns for zero-size allocations anyway.
I added the LLVM_ATTRIBUTE_RETURNS_NONNULL attribute back in r216192 and saw a significant speedup of Clang due to this, because it allowed us to avoid null checks in placement new operations.
But starting with Clang 3.7 or GCC 8, this doesn't seem to matter anymore: https://godbolt.org/z/QabXA-
In that case dropping the attribute seems fine. But please measure first.
Repository:
rL LLVM
https://reviews.llvm.org/D51317
More information about the llvm-commits
mailing list