Index: include/llvm/Support/Allocator.h =================================================================== --- include/llvm/Support/Allocator.h +++ include/llvm/Support/Allocator.h @@ -31,6 +31,10 @@ #include #include +#if LLVM_ADDRESS_SANITIZER_BUILD +#include +#endif + namespace llvm { /// \brief CRTP base class providing obvious overloads for the core \c @@ -221,6 +225,10 @@ // Without this, MemorySanitizer messages for values originated from here // will point to the allocation of the entire slab. __msan_allocated_memory(AlignedPtr, Size); + // Similarly, tell ASan about this space. +#if LLVM_ADDRESS_SANITIZER_BUILD + ASAN_UNPOISON_MEMORY_REGION(AlignedPtr, Size); +#endif return AlignedPtr; } @@ -228,12 +236,22 @@ size_t PaddedSize = Size + Alignment - 1; if (PaddedSize > SizeThreshold) { void *NewSlab = Allocator.Allocate(PaddedSize, 0); + + // We own the new slab and don't want anyone reading anyting other than + // pieces returned from this method. So poison the whole slab. +#if LLVM_ADDRESS_SANITIZER_BUILD + ASAN_POISON_MEMORY_REGION(NewSlab, PaddedSize); +#endif CustomSizedSlabs.push_back(std::make_pair(NewSlab, PaddedSize)); uintptr_t AlignedAddr = alignAddr(NewSlab, Alignment); assert(AlignedAddr + Size <= (uintptr_t)NewSlab + PaddedSize); char *AlignedPtr = (char*)AlignedAddr; __msan_allocated_memory(AlignedPtr, Size); + // Tell ASan about this space. +#if LLVM_ADDRESS_SANITIZER_BUILD + ASAN_UNPOISON_MEMORY_REGION(AlignedPtr, Size); +#endif return AlignedPtr; } @@ -245,13 +263,23 @@ char *AlignedPtr = (char*)AlignedAddr; CurPtr = AlignedPtr + Size; __msan_allocated_memory(AlignedPtr, Size); + // Similarly, tell ASan about this space. +#if LLVM_ADDRESS_SANITIZER_BUILD + ASAN_UNPOISON_MEMORY_REGION(AlignedPtr, Size); +#endif return AlignedPtr; } // Pull in base class overloads. using AllocatorBase::Allocate; - void Deallocate(const void * /*Ptr*/, size_t /*Size*/) {} + void Deallocate(const void * Ptr, size_t Size) { + // For speed reasons we don't want the BumpPtrAllocator itself to + // +#if LLVM_ADDRESS_SANITIZER_BUILD + ASAN_POISON_MEMORY_REGION(Ptr, Size); +#endif + } // Pull in base class overloads. using AllocatorBase::Deallocate; @@ -309,6 +337,13 @@ size_t AllocatedSlabSize = computeSlabSize(Slabs.size()); void *NewSlab = Allocator.Allocate(AllocatedSlabSize, 0); + + // We own the new slab and don't want anyone reading anyting other than + // pieces returned from this method. So poison the whole slab. +#if LLVM_ADDRESS_SANITIZER_BUILD + ASAN_POISON_MEMORY_REGION(NewSlab, AllocatedSlabSize); +#endif + Slabs.push_back(NewSlab); CurPtr = (char *)(NewSlab); End = ((char *)NewSlab) + AllocatedSlabSize;