[llvm-commits] [PATCH] Annotate BumpPtrAllocator for MemorySanitizer
Evgeniy Stepanov
eugenis at google.com
Mon Jan 28 06:13:27 PST 2013
Hi kcc,
This change helps MSan produce correct "Uninitialised value was created by" stack traces.
Declaration of __msan_allocated_memory is there so that we don't depend on msan_interface.h header from compiler-rt. Alternatively, we could make a copy of that header somewhere in LLVM tree.
http://llvm-reviews.chandlerc.com/D336
Files:
lib/Support/Allocator.cpp
Index: lib/Support/Allocator.cpp
===================================================================
--- lib/Support/Allocator.cpp
+++ lib/Support/Allocator.cpp
@@ -84,6 +84,13 @@
End = ((char*)CurSlab) + CurSlab->Size;
}
+#if defined(__has_feature) && __has_feature(memory_sanitizer)
+extern "C" void __msan_allocated_memory(void* data, size_t size);
+# define MSAN_ALLOCATED_MEMORY(p, s) __msan_allocated_memory(p, s)
+#else
+# define MSAN_ALLOCATED_MEMORY(p, s)
+#endif
+
/// Allocate - Allocate space at the specified alignment.
///
void *BumpPtrAllocator::Allocate(size_t Size, size_t Alignment) {
@@ -102,6 +109,7 @@
// Check if we can hold it.
if (Ptr + Size <= End) {
CurPtr = Ptr + Size;
+ MSAN_ALLOCATED_MEMORY(Ptr, Size);
return Ptr;
}
@@ -117,14 +125,16 @@
Ptr = AlignPtr((char*)(NewSlab + 1), Alignment);
assert((uintptr_t)Ptr + Size <= (uintptr_t)NewSlab + NewSlab->Size);
+ MSAN_ALLOCATED_MEMORY(Ptr, Size);
return Ptr;
}
// Otherwise, start a new slab and try again.
StartNewSlab();
Ptr = AlignPtr(CurPtr, Alignment);
CurPtr = Ptr + Size;
assert(CurPtr <= End && "Unable to allocate memory!");
+ MSAN_ALLOCATED_MEMORY(Ptr, Size);
return Ptr;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D336.1.patch
Type: text/x-patch
Size: 1240 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130128/978de971/attachment.bin>
More information about the llvm-commits
mailing list