[PATCH] Annotate BumpPtrAllocator for MemorySanitizer
Evgeniy Stepanov
eugenis at google.com
Wed Jan 30 06:10:07 PST 2013
PTAL.
Hi kcc, nicholas,
http://llvm-reviews.chandlerc.com/D336
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D336?vs=786&id=829#toc
Files:
lib/Support/Allocator.cpp
cmake/config-ix.cmake
include/llvm/Config/config.h.cmake
include/llvm/Support/Compiler.h
Index: lib/Support/Allocator.cpp
===================================================================
--- lib/Support/Allocator.cpp
+++ lib/Support/Allocator.cpp
@@ -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,9 @@
// Check if we can hold it.
if (Ptr + Size <= End) {
CurPtr = Ptr + Size;
+#if LLVM_ENABLE_MSAN_ANNOTATIONS
+ __msan_allocated_memory(Ptr, Size);
+#endif
return Ptr;
}
@@ -117,14 +121,20 @@
Ptr = AlignPtr((char*)(NewSlab + 1), Alignment);
assert((uintptr_t)Ptr + Size <= (uintptr_t)NewSlab + NewSlab->Size);
+#if LLVM_ENABLE_MSAN_ANNOTATIONS
+ __msan_allocated_memory(Ptr, Size);
+#endif
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!");
+#if LLVM_ENABLE_MSAN_ANNOTATIONS
+ __msan_allocated_memory(Ptr, Size);
+#endif
return Ptr;
}
Index: cmake/config-ix.cmake
===================================================================
--- cmake/config-ix.cmake
+++ cmake/config-ix.cmake
@@ -54,6 +54,8 @@
if( NOT PURE_WINDOWS )
check_include_file(pthread.h HAVE_PTHREAD_H)
endif()
+check_include_file(sanitizer/asan_interface.h HAVE_SANITIZER_ASAN_INTERFACE_H)
+check_include_file(sanitizer/msan_interface.h HAVE_SANITIZER_MSAN_INTERFACE_H)
check_include_file(setjmp.h HAVE_SETJMP_H)
check_include_file(signal.h HAVE_SIGNAL_H)
check_include_file(stdint.h HAVE_STDINT_H)
Index: include/llvm/Config/config.h.cmake
===================================================================
--- include/llvm/Config/config.h.cmake
+++ include/llvm/Config/config.h.cmake
@@ -468,6 +468,12 @@
/* Define to 1 if the system has the type `u_int64_t'. */
#cmakedefine HAVE_U_INT64_T ${HAVE_U_INT64_T}
+/* Define to 1 if you have the <sanitizer/asan_interface.h> header file. */
+#cmakedefine HAVE_SANITIZER_ASAN_INTERFACE_H ${HAVE_SANITIZER_ASAN_INTERFACE_H}
+
+/* Define to 1 if you have the <sanitizer/msan_interface.h> header file. */
+#cmakedefine HAVE_SANITIZER_MSAN_INTERFACE_H ${HAVE_SANITIZER_MSAN_INTERFACE_H}
+
/* Define to 1 if you have the <valgrind/valgrind.h> header file. */
#cmakedefine HAVE_VALGRIND_VALGRIND_H ${HAVE_VALGRIND_VALGRIND_H}
Index: include/llvm/Support/Compiler.h
===================================================================
--- include/llvm/Support/Compiler.h
+++ include/llvm/Support/Compiler.h
@@ -15,6 +15,8 @@
#ifndef LLVM_SUPPORT_COMPILER_H
#define LLVM_SUPPORT_COMPILER_H
+#include "llvm/Config/config.h"
+
#ifndef __has_feature
# define __has_feature(x) 0
#endif
@@ -293,4 +295,38 @@
# define LLVM_FUNCTION_NAME __func__
#endif
+/// \macro LLVM_ENABLE_ASAN_ANNOTATIONS
+/// \brief Are AddressSanitizer annotations available.
+#if defined(HAVE_SANITIZER_ASAN_INTERFACE_H)
+# include <sanitizer/asan_interface.h>
+# define LLVM_ENABLE_ASAN_ANNOTATIONS 1
+#else
+# define LLVM_ENABLE_ASAN_ANNOTATIONS 0
+#endif
+
+/// \macro LLVM_ADDRESS_SANITIZER_BUILD
+/// \brief Whether LLVM itself is built with AddressSanitizer instrumentation.
+#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
+# define LLVM_ADDRESS_SANITIZER_BUILD 1
+#else
+# define LLVM_ADDRESS_SANITIZER_BUILD 0
+#endif
+
+/// \macro LLVM_ENABLE_MSAN_ANNOTATIONS
+/// \brief Are MemorySanitizer annotations available.
+#if defined(HAVE_SANITIZER_MSAN_INTERFACE_H)
+# include <sanitizer/msan_interface.h>
+# define LLVM_ENABLE_MSAN_ANNOTATIONS 1
+#else
+# define LLVM_ENABLE_MSAN_ANNOTATIONS 0
+#endif
+
+/// \macro LLVM_MEMORY_SANITIZER_BUILD
+/// \brief Whether LLVM itself is built with MemorySanitizer instrumentation.
+#if __has_feature(memory_sanitizer)
+# define LLVM_MEMORY_SANITIZER_BUILD 1
+#else
+# define LLVM_MEMORY_SANITIZER_BUILD 0
+#endif
+
#endif
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D336.2.patch
Type: text/x-patch
Size: 4063 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130130/13407094/attachment.bin>
More information about the llvm-commits
mailing list