[llvm] 22ee510 - [Support] Remove incorrect noalias return attribute in BumpPtrAllocator

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 20 00:24:16 PST 2022


Author: Nikita Popov
Date: 2022-01-20T09:17:35+01:00
New Revision: 22ee510dac9440a74b2e5b3fe3ff13ccdbf55af3

URL: https://github.com/llvm/llvm-project/commit/22ee510dac9440a74b2e5b3fe3ff13ccdbf55af3
DIFF: https://github.com/llvm/llvm-project/commit/22ee510dac9440a74b2e5b3fe3ff13ccdbf55af3.diff

LOG: [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

Added: 
    

Modified: 
    llvm/include/llvm/Support/Allocator.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Support/Allocator.h b/llvm/include/llvm/Support/Allocator.h
index 9e8ce4e36197c..3b1d11e3f75f8 100644
--- a/llvm/include/llvm/Support/Allocator.h
+++ b/llvm/include/llvm/Support/Allocator.h
@@ -141,8 +141,10 @@ class BumpPtrAllocatorImpl
   }
 
   /// Allocate space at the specified alignment.
-  LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void *
-  Allocate(size_t Size, Align Alignment) {
+  // This method is *not* marked noalias, because
+  // SpecificBumpPtrAllocator::DestroyAll() loops over all allocations, and
+  // that loop is not based on the Allocate() return value.
+  LLVM_ATTRIBUTE_RETURNS_NONNULL void *Allocate(size_t Size, Align Alignment) {
     // Keep track of how many bytes we've allocated.
     BytesAllocated += Size;
 
@@ -198,7 +200,7 @@ class BumpPtrAllocatorImpl
     return AlignedPtr;
   }
 
-  inline LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void *
+  inline LLVM_ATTRIBUTE_RETURNS_NONNULL void *
   Allocate(size_t Size, size_t Alignment) {
     assert(Alignment > 0 && "0-byte alignment is not allowed. Use 1 instead.");
     return Allocate(Size, Align(Alignment));


        


More information about the llvm-commits mailing list