Skip to content

Commit 22ee510

Browse files
committed
[Support] Remove incorrect noalias return attribute in BumpPtrAllocator
The memory returned by the Allocate() function is also otherwise accessible -- and is indeed accessed by the DestroyAll() method of SpecificBumpPtrAlloactor. This is a violation of the noalias return contract. This should address the issue reported in https://reviews.llvm.org/D116728#3252464. Differential Revision: https://reviews.llvm.org/D117664
1 parent 8f811ef commit 22ee510

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

llvm/include/llvm/Support/Allocator.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,10 @@ class BumpPtrAllocatorImpl
141141
}
142142

143143
/// Allocate space at the specified alignment.
144-
LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void *
145-
Allocate(size_t Size, Align Alignment) {
144+
// This method is *not* marked noalias, because
145+
// SpecificBumpPtrAllocator::DestroyAll() loops over all allocations, and
146+
// that loop is not based on the Allocate() return value.
147+
LLVM_ATTRIBUTE_RETURNS_NONNULL void *Allocate(size_t Size, Align Alignment) {
146148
// Keep track of how many bytes we've allocated.
147149
BytesAllocated += Size;
148150

@@ -198,7 +200,7 @@ class BumpPtrAllocatorImpl
198200
return AlignedPtr;
199201
}
200202

201-
inline LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void *
203+
inline LLVM_ATTRIBUTE_RETURNS_NONNULL void *
202204
Allocate(size_t Size, size_t Alignment) {
203205
assert(Alignment > 0 && "0-byte alignment is not allowed. Use 1 instead.");
204206
return Allocate(Size, Align(Alignment));

0 commit comments

Comments
 (0)