Annotate BumpPtrAllocator for MemorySanitizer.

This change adds MemorySanitizer annotations to BumpPtrAllocator to
improve report quality.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@174051 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Evgeniy Stepanov
2013-01-31 09:58:59 +00:00
parent e22df330a3
commit ea2d8780e9
4 changed files with 29 additions and 0 deletions

View File

@@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/Allocator.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/DataTypes.h"
#include "llvm/Support/Memory.h"
#include "llvm/Support/Recycler.h"
@@ -102,6 +103,10 @@ void *BumpPtrAllocator::Allocate(size_t Size, size_t Alignment) {
// Check if we can hold it.
if (Ptr + Size <= End) {
CurPtr = Ptr + Size;
// Update the allocation point of this memory block in MemorySanitizer.
// Without this, MemorySanitizer reports for values originating from it will
// point to the allocation point of the entire slab.
__msan_allocated_memory(Ptr, Size);
return Ptr;
}
@@ -117,6 +122,7 @@ void *BumpPtrAllocator::Allocate(size_t Size, size_t Alignment) {
Ptr = AlignPtr((char*)(NewSlab + 1), Alignment);
assert((uintptr_t)Ptr + Size <= (uintptr_t)NewSlab + NewSlab->Size);
__msan_allocated_memory(Ptr, Size);
return Ptr;
}
@@ -125,6 +131,7 @@ void *BumpPtrAllocator::Allocate(size_t Size, size_t Alignment) {
Ptr = AlignPtr(CurPtr, Alignment);
CurPtr = Ptr + Size;
assert(CurPtr <= End && "Unable to allocate memory!");
__msan_allocated_memory(Ptr, Size);
return Ptr;
}