<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jan 29, 2013 at 6:33 PM, Evgeniy Stepanov <span dir="ltr"><<a href="mailto:eugeni.stepanov@gmail.com" target="_blank">eugeni.stepanov@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: eugenis<br>
Date: Tue Jan 29 08:33:29 2013<br>
New Revision: 173800<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=173800&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=173800&view=rev</a><br>
Log:<br>
[msan] Cleanup public interface header.<br>
<br>
Moved everything users are not supposed to use to a private interface header.<br>
Documented all public interfaces. Made them safe to use even if built without<br>
MemorySanitizer.<br>
<br>
Added:<br>
compiler-rt/trunk/lib/msan/msan_interface_internal.h (with props)<br>
Modified:<br>
compiler-rt/trunk/include/sanitizer/msan_interface.h<br>
compiler-rt/trunk/lib/msan/msan.cc<br>
compiler-rt/trunk/lib/msan/msan.h<br>
compiler-rt/trunk/lib/msan/tests/CMakeLists.txt<br>
compiler-rt/trunk/lib/msan/tests/msan_test.cc<br>
compiler-rt/trunk/lib/msan/tests/msandr_test_so.cc<br>
compiler-rt/trunk/lib/msan/tests/msandr_test_so.h<br>
<br>
Modified: compiler-rt/trunk/include/sanitizer/msan_interface.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/include/sanitizer/msan_interface.h?rev=173800&r1=173799&r2=173800&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/include/sanitizer/msan_interface.h?rev=173800&r1=173799&r2=173800&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/include/sanitizer/msan_interface.h (original)<br>
+++ compiler-rt/trunk/include/sanitizer/msan_interface.h Tue Jan 29 08:33:29 2013<br>
@@ -24,103 +24,99 @@ using __sanitizer::u32;<br>
extern "C" {<br>
#endif<br>
<br>
-// FIXME: document all interface functions.<br>
+#if defined(__has_feature) && __has_feature(memory_sanitizer)<br></blockquote><div><br></div><div style>I afraid this is not going to compile with gcc </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
-SANITIZER_INTERFACE_ATTRIBUTE<br>
-int __msan_get_track_origins();<br>
+ /* Returns a string describing a stack origin.<br>
+ Return NULL if the origin is invalid, or is not a stack origin. */<br>
+ SANITIZER_INTERFACE_ATTRIBUTE<br>
+ const char *__msan_get_origin_descr_if_stack(u32 id);<br>
+<br>
+<br>
+ /* Set raw origin for the memory range. */<br>
+ SANITIZER_INTERFACE_ATTRIBUTE<br>
+ void __msan_set_origin(void *a, uptr size, u32 origin);<br>
+<br>
+ /* Get raw origin for an address. */<br>
+ SANITIZER_INTERFACE_ATTRIBUTE<br>
+ u32 __msan_get_origin(void *a);<br>
+<br>
+ /* Returns non-zero if tracking origins. */<br>
+ SANITIZER_INTERFACE_ATTRIBUTE<br>
+ int __msan_get_track_origins();<br>
+<br>
+ /* Returns the origin id of the latest UMR in the calling thread. */<br>
+ SANITIZER_INTERFACE_ATTRIBUTE<br>
+ u32 __msan_get_umr_origin();<br>
+<br>
+ /* Make memory region fully initialized (without changing its contents). */<br>
+ SANITIZER_INTERFACE_ATTRIBUTE<br>
+ void __msan_unpoison(void *a, uptr size);<br>
+<br>
+ /* Make memory region fully uninitialized (without changing its contents). */<br>
+ SANITIZER_INTERFACE_ATTRIBUTE<br>
+ void __msan_poison(void *a, uptr size);<br>
+<br>
+ /* Make memory region partially uninitialized (without changing its contents).<br>
+ */<br>
+ SANITIZER_INTERFACE_ATTRIBUTE<br>
+ void __msan_partial_poison(void* data, void* shadow, uptr size);<br>
+<br>
+ /* Returns the offset of the first (at least partially) poisoned byte in the<br>
+ memory range, or -1 if the whole range is good. */<br>
+ SANITIZER_INTERFACE_ATTRIBUTE<br>
+ sptr __msan_test_shadow(const void *x, uptr size);<br>
+<br>
+ /* Set exit code when error(s) were detected.<br>
+ Value of 0 means don't change the program exit code. */<br>
+ SANITIZER_INTERFACE_ATTRIBUTE<br>
+ void __msan_set_exit_code(int exit_code);<br>
+<br>
+ /* For testing:<br>
+ __msan_set_expect_umr(1);<br>
+ ... some buggy code ...<br>
+ __msan_set_expect_umr(0);<br>
+ The last line will verify that a UMR happened. */<br>
+ SANITIZER_INTERFACE_ATTRIBUTE<br>
+ void __msan_set_expect_umr(int expect_umr);<br>
+<br>
+ /* Print shadow and origin for the memory range to stdout in a human-readable<br>
+ format. */<br>
+ SANITIZER_INTERFACE_ATTRIBUTE<br>
+ void __msan_print_shadow(const void *x, uptr size);<br>
+<br>
+ /* Print current function arguments shadow and origin to stdout in a<br>
+ human-readable format. */<br>
+ SANITIZER_INTERFACE_ATTRIBUTE<br>
+ void __msan_print_param_shadow();<br>
+<br>
+ /* Returns true if running under a dynamic tool (DynamoRio-based). */<br>
+ SANITIZER_INTERFACE_ATTRIBUTE<br>
+ int __msan_has_dynamic_component();<br>
+<br>
+ /* Tell MSan about newly allocated memory (ex.: custom allocator).<br>
+ Memory will be marked uninitialized, with origin at the call site. */<br>
+ SANITIZER_INTERFACE_ATTRIBUTE<br>
+ void __msan_allocated_memory(void* data, uptr size);<br>
+<br>
+#else // __has_feature(memory_sanitizer)<br>
+<br>
+#define __msan_get_origin_descr_if_stack(u32 id) ((const char*)0)<br>
+#define __msan_set_origin(void *a, uptr size, u32 origin)<br>
+#define __msan_get_origin(void *a) ((u32)-1)<br>
+#define __msan_get_track_origins() (0)<br>
+#define __msan_get_umr_origin() ((u32)-1)<br>
+#define __msan_unpoison(void *a, uptr size)<br>
+#define __msan_poison(void *a, uptr size)<br>
+#define __msan_partial_poison(void* data, void* shadow, uptr size)<br>
+#define __msan_test_shadow(const void *x, uptr size) ((sptr)-1)<br>
+#define __msan_set_exit_code(int exit_code)<br>
+#define __msan_set_expect_umr(int expect_umr)<br>
+#define __msan_print_shadow(const void *x, uptr size)<br>
+#define __msan_print_param_shadow()<br>
+#define __msan_has_dynamic_component() (0)<br>
+#define __msan_allocated_memory(data, size)<br>
<br>
-SANITIZER_INTERFACE_ATTRIBUTE<br>
-void __msan_init();<br>
-<br>
-// Print a warning and maybe return.<br>
-// This function can die based on flags()->exit_code.<br>
-SANITIZER_INTERFACE_ATTRIBUTE<br>
-void __msan_warning();<br>
-<br>
-// Print a warning and die.<br>
-// Intrumentation inserts calls to this function when building in "fast" mode<br>
-// (i.e. -mllvm -msan-keep-going)<br>
-SANITIZER_INTERFACE_ATTRIBUTE __attribute__((noreturn))<br>
-void __msan_warning_noreturn();<br>
-<br>
-SANITIZER_INTERFACE_ATTRIBUTE<br>
-void __msan_unpoison(void *a, uptr size);<br>
-SANITIZER_INTERFACE_ATTRIBUTE<br>
-void __msan_clear_and_unpoison(void *a, uptr size);<br>
-SANITIZER_INTERFACE_ATTRIBUTE<br>
-void* __msan_memcpy(void *dst, const void *src, uptr size);<br>
-SANITIZER_INTERFACE_ATTRIBUTE<br>
-void* __msan_memset(void *s, int c, uptr n);<br>
-SANITIZER_INTERFACE_ATTRIBUTE<br>
-void* __msan_memmove(void* dest, const void* src, uptr n);<br>
-SANITIZER_INTERFACE_ATTRIBUTE<br>
-void __msan_copy_poison(void *dst, const void *src, uptr size);<br>
-SANITIZER_INTERFACE_ATTRIBUTE<br>
-void __msan_copy_origin(void *dst, const void *src, uptr size);<br>
-SANITIZER_INTERFACE_ATTRIBUTE<br>
-void __msan_move_poison(void *dst, const void *src, uptr size);<br>
-SANITIZER_INTERFACE_ATTRIBUTE<br>
-void __msan_poison(void *a, uptr size);<br>
-SANITIZER_INTERFACE_ATTRIBUTE<br>
-void __msan_poison_stack(void *a, uptr size);<br>
-<br>
-// Copy size bytes from src to dst and unpoison the result.<br>
-// Useful to implement unsafe loads.<br>
-SANITIZER_INTERFACE_ATTRIBUTE<br>
-void __msan_load_unpoisoned(void *src, uptr size, void *dst);<br>
-<br>
-// Returns the offset of the first (at least partially) poisoned byte,<br>
-// or -1 if the whole range is good.<br>
-SANITIZER_INTERFACE_ATTRIBUTE<br>
-sptr __msan_test_shadow(const void *x, uptr size);<br>
-<br>
-SANITIZER_INTERFACE_ATTRIBUTE<br>
-void __msan_set_origin(void *a, uptr size, u32 origin);<br>
-SANITIZER_INTERFACE_ATTRIBUTE<br>
-void __msan_set_alloca_origin(void *a, uptr size, const char *descr);<br>
-SANITIZER_INTERFACE_ATTRIBUTE<br>
-u32 __msan_get_origin(void *a);<br>
-<br>
-SANITIZER_INTERFACE_ATTRIBUTE<br>
-void __msan_clear_on_return();<br>
-<br>
-// Default: -1 (don't exit on error).<br>
-SANITIZER_INTERFACE_ATTRIBUTE<br>
-void __msan_set_exit_code(int exit_code);<br>
-<br>
-SANITIZER_INTERFACE_ATTRIBUTE<br>
-int __msan_set_poison_in_malloc(int do_poison);<br>
-<br>
-// For testing.<br>
-SANITIZER_INTERFACE_ATTRIBUTE<br>
-void __msan_set_expect_umr(int expect_umr);<br>
-SANITIZER_INTERFACE_ATTRIBUTE<br>
-void __msan_break_optimization(void *x);<br>
-SANITIZER_INTERFACE_ATTRIBUTE<br>
-void __msan_print_shadow(const void *x, uptr size);<br>
-SANITIZER_INTERFACE_ATTRIBUTE<br>
-void __msan_print_param_shadow();<br>
-SANITIZER_INTERFACE_ATTRIBUTE<br>
-int __msan_has_dynamic_component();<br>
-<br>
-// Returns x such that %fs:x is the first byte of __msan_retval_tls.<br>
-SANITIZER_INTERFACE_ATTRIBUTE<br>
-int __msan_get_retval_tls_offset();<br>
-SANITIZER_INTERFACE_ATTRIBUTE<br>
-int __msan_get_param_tls_offset();<br>
-<br>
-// For testing.<br>
-SANITIZER_INTERFACE_ATTRIBUTE<br>
-u32 __msan_get_origin_tls();<br>
-SANITIZER_INTERFACE_ATTRIBUTE<br>
-const char *__msan_get_origin_descr_if_stack(u32 id);<br>
-SANITIZER_INTERFACE_ATTRIBUTE<br>
-void __msan_partial_poison(void* data, void* shadow, uptr size);<br>
-<br>
-// Tell MSan about newly allocated memory (ex.: custom allocator).<br>
-// Memory will be marked uninitialized, with origin at the call site.<br>
-SANITIZER_INTERFACE_ATTRIBUTE<br>
-void __msan_allocated_memory(void* data, uptr size);<br>
+#endif // __has_feature(memory_sanitizer)<br>
<br>
#ifdef __cplusplus<br>
} // extern "C"<br>
<br>
Modified: compiler-rt/trunk/lib/msan/msan.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan.cc?rev=173800&r1=173799&r2=173800&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan.cc?rev=173800&r1=173799&r2=173800&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/msan/msan.cc (original)<br>
+++ compiler-rt/trunk/lib/msan/msan.cc Tue Jan 29 08:33:29 2013<br>
@@ -306,8 +306,6 @@ int __msan_set_poison_in_malloc(int do_p<br>
return old;<br>
}<br>
<br>
-void __msan_break_optimization(void *x) { }<br>
-<br>
int __msan_has_dynamic_component() {<br>
return msan_running_under_dr;<br>
}<br>
@@ -413,6 +411,6 @@ u32 __msan_get_origin(void *a) {<br>
return *(u32*)origin_ptr;<br>
}<br>
<br>
-u32 __msan_get_origin_tls() {<br>
+u32 __msan_get_umr_origin() {<br>
return __msan_origin_tls;<br>
}<br>
<br>
Modified: compiler-rt/trunk/lib/msan/msan.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan.h?rev=173800&r1=173799&r2=173800&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan.h?rev=173800&r1=173799&r2=173800&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/msan/msan.h (original)<br>
+++ compiler-rt/trunk/lib/msan/msan.h Tue Jan 29 08:33:29 2013<br>
@@ -17,7 +17,7 @@<br>
<br>
#include "sanitizer_common/sanitizer_internal_defs.h"<br>
#include "sanitizer_common/sanitizer_stacktrace.h"<br>
-#include "sanitizer/msan_interface.h"<br>
+#include "msan_interface_internal.h"<br>
#include "msan_flags.h"<br>
<br>
#define MEM_TO_SHADOW(mem) (((uptr)mem) & ~0x400000000000ULL)<br>
<br>
Added: compiler-rt/trunk/lib/msan/msan_interface_internal.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_interface_internal.h?rev=173800&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_interface_internal.h?rev=173800&view=auto</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/msan/msan_interface_internal.h (added)<br>
+++ compiler-rt/trunk/lib/msan/msan_interface_internal.h Tue Jan 29 08:33:29 2013<br>
@@ -0,0 +1,120 @@<br>
+//===-- msan_interface_internal.h -------------------------------*- C++ -*-===//<br>
+//<br>
+// The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+//<br>
+// This file is a part of MemorySanitizer.<br>
+//<br>
+// Private MSan interface header.<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#ifndef MSAN_INTERFACE_INTERNAL_H<br>
+#define MSAN_INTERFACE_INTERNAL_H<br>
+<br>
+#include <sanitizer/common_interface_defs.h><br>
+<br>
+extern "C" {<br>
+<br>
+// FIXME: document all interface functions.<br>
+<br>
+SANITIZER_INTERFACE_ATTRIBUTE<br>
+int __msan_get_track_origins();<br>
+<br>
+SANITIZER_INTERFACE_ATTRIBUTE<br>
+void __msan_init();<br>
+<br>
+// Print a warning and maybe return.<br>
+// This function can die based on flags()->exit_code.<br>
+SANITIZER_INTERFACE_ATTRIBUTE<br>
+void __msan_warning();<br>
+<br>
+// Print a warning and die.<br>
+// Intrumentation inserts calls to this function when building in "fast" mode<br>
+// (i.e. -mllvm -msan-keep-going)<br>
+SANITIZER_INTERFACE_ATTRIBUTE __attribute__((noreturn))<br>
+void __msan_warning_noreturn();<br>
+<br>
+SANITIZER_INTERFACE_ATTRIBUTE<br>
+void __msan_unpoison(void *a, uptr size);<br>
+SANITIZER_INTERFACE_ATTRIBUTE<br>
+void __msan_clear_and_unpoison(void *a, uptr size);<br>
+SANITIZER_INTERFACE_ATTRIBUTE<br>
+void* __msan_memcpy(void *dst, const void *src, uptr size);<br>
+SANITIZER_INTERFACE_ATTRIBUTE<br>
+void* __msan_memset(void *s, int c, uptr n);<br>
+SANITIZER_INTERFACE_ATTRIBUTE<br>
+void* __msan_memmove(void* dest, const void* src, uptr n);<br>
+SANITIZER_INTERFACE_ATTRIBUTE<br>
+void __msan_copy_poison(void *dst, const void *src, uptr size);<br>
+SANITIZER_INTERFACE_ATTRIBUTE<br>
+void __msan_copy_origin(void *dst, const void *src, uptr size);<br>
+SANITIZER_INTERFACE_ATTRIBUTE<br>
+void __msan_move_poison(void *dst, const void *src, uptr size);<br>
+SANITIZER_INTERFACE_ATTRIBUTE<br>
+void __msan_poison(void *a, uptr size);<br>
+SANITIZER_INTERFACE_ATTRIBUTE<br>
+void __msan_poison_stack(void *a, uptr size);<br>
+<br>
+// Copy size bytes from src to dst and unpoison the result.<br>
+// Useful to implement unsafe loads.<br>
+SANITIZER_INTERFACE_ATTRIBUTE<br>
+void __msan_load_unpoisoned(void *src, uptr size, void *dst);<br>
+<br>
+// Returns the offset of the first (at least partially) poisoned byte,<br>
+// or -1 if the whole range is good.<br>
+SANITIZER_INTERFACE_ATTRIBUTE<br>
+sptr __msan_test_shadow(const void *x, uptr size);<br>
+<br>
+SANITIZER_INTERFACE_ATTRIBUTE<br>
+void __msan_set_origin(void *a, uptr size, u32 origin);<br>
+SANITIZER_INTERFACE_ATTRIBUTE<br>
+void __msan_set_alloca_origin(void *a, uptr size, const char *descr);<br>
+SANITIZER_INTERFACE_ATTRIBUTE<br>
+u32 __msan_get_origin(void *a);<br>
+<br>
+SANITIZER_INTERFACE_ATTRIBUTE<br>
+void __msan_clear_on_return();<br>
+<br>
+// Default: -1 (don't exit on error).<br>
+SANITIZER_INTERFACE_ATTRIBUTE<br>
+void __msan_set_exit_code(int exit_code);<br>
+<br>
+SANITIZER_INTERFACE_ATTRIBUTE<br>
+int __msan_set_poison_in_malloc(int do_poison);<br>
+<br>
+// For testing.<br>
+SANITIZER_INTERFACE_ATTRIBUTE<br>
+void __msan_set_expect_umr(int expect_umr);<br>
+SANITIZER_INTERFACE_ATTRIBUTE<br>
+void __msan_print_shadow(const void *x, uptr size);<br>
+SANITIZER_INTERFACE_ATTRIBUTE<br>
+void __msan_print_param_shadow();<br>
+SANITIZER_INTERFACE_ATTRIBUTE<br>
+int __msan_has_dynamic_component();<br>
+<br>
+// Returns x such that %fs:x is the first byte of __msan_retval_tls.<br>
+SANITIZER_INTERFACE_ATTRIBUTE<br>
+int __msan_get_retval_tls_offset();<br>
+SANITIZER_INTERFACE_ATTRIBUTE<br>
+int __msan_get_param_tls_offset();<br>
+<br>
+// For testing.<br>
+SANITIZER_INTERFACE_ATTRIBUTE<br>
+u32 __msan_get_umr_origin();<br>
+SANITIZER_INTERFACE_ATTRIBUTE<br>
+const char *__msan_get_origin_descr_if_stack(u32 id);<br>
+SANITIZER_INTERFACE_ATTRIBUTE<br>
+void __msan_partial_poison(void* data, void* shadow, uptr size);<br>
+<br>
+// Tell MSan about newly allocated memory (ex.: custom allocator).<br>
+// Memory will be marked uninitialized, with origin at the call site.<br>
+SANITIZER_INTERFACE_ATTRIBUTE<br>
+void __msan_allocated_memory(void* data, uptr size);<br>
+<br>
+} // extern "C"<br>
+<br>
+#endif // MSAN_INTERFACE_INTERNAL_H<br>
<br>
Propchange: compiler-rt/trunk/lib/msan/msan_interface_internal.h<br>
------------------------------------------------------------------------------<br>
svn:eol-style = LF<br>
<br>
Modified: compiler-rt/trunk/lib/msan/tests/CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/tests/CMakeLists.txt?rev=173800&r1=173799&r2=173800&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/tests/CMakeLists.txt?rev=173800&r1=173799&r2=173800&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/msan/tests/CMakeLists.txt (original)<br>
+++ compiler-rt/trunk/lib/msan/tests/CMakeLists.txt Tue Jan 29 08:33:29 2013<br>
@@ -32,7 +32,10 @@ set(MSAN_LIBCXX_LINK_FLAGS<br>
<br>
# Unittest sources and build flags.<br>
set(MSAN_UNITTEST_SOURCE msan_test.cc)<br>
-set(MSAN_UNITTEST_HEADERS msandr_test_so.h)<br>
+set(MSAN_UNITTEST_HEADERS<br>
+ msandr_test_so.h<br>
+ ../../../include/sanitizer/msan_interface.h<br>
+)<br>
set(MSANDR_UNITTEST_SOURCE msandr_test_so.cc)<br>
set(MSAN_UNITTEST_COMMON_CFLAGS<br>
-I${MSAN_LIBCXX_PATH}/include<br>
<br>
Modified: compiler-rt/trunk/lib/msan/tests/msan_test.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/tests/msan_test.cc?rev=173800&r1=173799&r2=173800&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/tests/msan_test.cc?rev=173800&r1=173799&r2=173800&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/msan/tests/msan_test.cc (original)<br>
+++ compiler-rt/trunk/lib/msan/tests/msan_test.cc Tue Jan 29 08:33:29 2013<br>
@@ -74,7 +74,7 @@ static bool TrackingOrigins() {<br>
action; \<br>
__msan_set_expect_umr(0); \<br>
if (TrackingOrigins()) \<br>
- EXPECT_EQ(origin, __msan_get_origin_tls()); \<br>
+ EXPECT_EQ(origin, __msan_get_umr_origin()); \<br>
} while (0)<br>
<br>
#define EXPECT_UMR_S(action, stack_origin) \<br>
@@ -82,7 +82,7 @@ static bool TrackingOrigins() {<br>
__msan_set_expect_umr(1); \<br>
action; \<br>
__msan_set_expect_umr(0); \<br>
- u32 id = __msan_get_origin_tls(); \<br>
+ u32 id = __msan_get_umr_origin(); \<br>
const char *str = __msan_get_origin_descr_if_stack(id); \<br>
if (!str || strcmp(str, stack_origin)) { \<br>
fprintf(stderr, "EXPECT_POISONED_S: id=%u %s, %s", \<br>
@@ -167,6 +167,14 @@ static volatile int g_1 = 1;<br>
S4 a_s4[100];<br>
S8 a_s8[100];<br>
<br>
+// Check that malloc poisons memory.<br>
+// A lot of tests below depend on this.<br>
+TEST(MemorySanitizerSanity, PoisonInMalloc) {<br>
+ int *x = (int*)malloc(sizeof(int));<br>
+ EXPECT_POISONED(*x);<br>
+ free(x);<br>
+}<br>
+<br>
TEST(MemorySanitizer, NegativeTest1) {<br>
S4 *x = GetPoisoned<S4>();<br>
if (g_one)<br>
@@ -221,7 +229,7 @@ TEST(MemorySanitizer, Phi1) {<br>
if (g_one) {<br>
c = *GetPoisoned<S4>();<br>
} else {<br>
- __msan_break_optimization(0);<br>
+ break_optimization(0);<br>
c = 0;<br>
}<br>
EXPECT_POISONED(c);<br>
@@ -393,14 +401,14 @@ NOINLINE static int GetPoisonedZero() {<br>
TEST(MemorySanitizer, LoadFromDirtyAddress) {<br>
int *a = new int;<br>
*a = 0;<br>
- EXPECT_UMR(__msan_break_optimization((void*)(U8)a[GetPoisonedZero()]));<br>
+ EXPECT_UMR(break_optimization((void*)(U8)a[GetPoisonedZero()]));<br>
delete a;<br>
}<br>
<br>
TEST(MemorySanitizer, StoreToDirtyAddress) {<br>
int *a = new int;<br>
EXPECT_UMR(a[GetPoisonedZero()] = 0);<br>
- __msan_break_optimization(a);<br>
+ break_optimization(a);<br>
delete a;<br>
}<br>
<br>
@@ -412,12 +420,12 @@ NOINLINE void StackTestFunc() {<br>
S2 ok2 = 1;<br>
S1 p1;<br>
S1 ok1 = 1;<br>
- __msan_break_optimization(&p4);<br>
- __msan_break_optimization(&ok4);<br>
- __msan_break_optimization(&p2);<br>
- __msan_break_optimization(&ok2);<br>
- __msan_break_optimization(&p1);<br>
- __msan_break_optimization(&ok1);<br>
+ break_optimization(&p4);<br>
+ break_optimization(&ok4);<br>
+ break_optimization(&p2);<br>
+ break_optimization(&ok2);<br>
+ break_optimization(&p1);<br>
+ break_optimization(&ok1);<br>
<br>
EXPECT_POISONED(p4);<br>
EXPECT_POISONED(p2);<br>
@@ -433,7 +441,7 @@ TEST(MemorySanitizer, StackTest) {<br>
<br>
NOINLINE void StackStressFunc() {<br>
int foo[10000];<br>
- __msan_break_optimization(foo);<br>
+ break_optimization(foo);<br>
}<br>
<br>
TEST(MemorySanitizer, DISABLED_StackStressTest) {<br>
@@ -445,7 +453,7 @@ template<class T><br>
void TestFloatingPoint() {<br>
static volatile T v;<br>
static T g[100];<br>
- __msan_break_optimization(&g);<br>
+ break_optimization(&g);<br>
T *x = GetPoisoned<T>();<br>
T *y = GetPoisoned<T>(1);<br>
EXPECT_POISONED(*x);<br>
@@ -723,7 +731,7 @@ TEST(MemorySanitizer, strtold) {<br>
<br>
TEST(MemorySanitizer, sprintf) { // NOLINT<br>
char buff[10];<br>
- __msan_break_optimization(buff);<br>
+ break_optimization(buff);<br>
EXPECT_POISONED(buff[0]);<br>
int res = sprintf(buff, "%d", 1234567); // NOLINT<br>
assert(res == 7);<br>
@@ -737,7 +745,7 @@ TEST(MemorySanitizer, sprintf) { // NOL<br>
<br>
TEST(MemorySanitizer, snprintf) {<br>
char buff[10];<br>
- __msan_break_optimization(buff);<br>
+ break_optimization(buff);<br>
EXPECT_POISONED(buff[0]);<br>
int res = snprintf(buff, sizeof(buff), "%d", 1234567);<br>
assert(res == 7);<br>
@@ -752,7 +760,7 @@ TEST(MemorySanitizer, snprintf) {<br>
TEST(MemorySanitizer, swprintf) {<br>
wchar_t buff[10];<br>
assert(sizeof(wchar_t) == 4);<br>
- __msan_break_optimization(buff);<br>
+ break_optimization(buff);<br>
EXPECT_POISONED(buff[0]);<br>
int res = swprintf(buff, 9, L"%d", 1234567);<br>
assert(res == 7);<br>
@@ -777,8 +785,8 @@ TEST(MemorySanitizer, wcstombs) {<br>
TEST(MemorySanitizer, gettimeofday) {<br>
struct timeval tv;<br>
struct timezone tz;<br>
- __msan_break_optimization(&tv);<br>
- __msan_break_optimization(&tz);<br>
+ break_optimization(&tv);<br>
+ break_optimization(&tz);<br>
assert(sizeof(tv) == 16);<br>
assert(sizeof(tz) == 8);<br>
EXPECT_POISONED(tv.tv_sec);<br>
@@ -815,8 +823,8 @@ TEST(MemorySanitizer, mmap) {<br>
// FIXME: check why msandr does nt handle fcvt.<br>
TEST(MemorySanitizer, fcvt) {<br>
int a, b;<br>
- __msan_break_optimization(&a);<br>
- __msan_break_optimization(&b);<br>
+ break_optimization(&a);<br>
+ break_optimization(&b);<br>
EXPECT_POISONED(a);<br>
EXPECT_POISONED(b);<br>
char *str = fcvt(12345.6789, 10, &a, &b);<br>
@@ -824,20 +832,12 @@ TEST(MemorySanitizer, fcvt) {<br>
EXPECT_NOT_POISONED(b);<br>
}<br>
<br>
-TEST(MemorySanitizer, LoadUnpoisoned) {<br>
- S8 s = *GetPoisoned<S8>();<br>
- EXPECT_POISONED(s);<br>
- S8 safe = *GetPoisoned<S8>();<br>
- __msan_load_unpoisoned(&s, sizeof(s), &safe);<br>
- EXPECT_NOT_POISONED(safe);<br>
-}<br>
-<br>
struct StructWithDtor {<br>
~StructWithDtor();<br>
};<br>
<br>
NOINLINE StructWithDtor::~StructWithDtor() {<br>
- __msan_break_optimization(0);<br>
+ break_optimization(0);<br>
}<br>
<br>
TEST(MemorySanitizer, Invoke) {<br>
@@ -1106,7 +1106,7 @@ NOINLINE StructWithHole ReturnStructWith<br>
<br>
TEST(MemorySanitizer, StructWithHole) {<br>
StructWithHole a = ReturnStructWithHole();<br>
- __msan_break_optimization(&a);<br>
+ break_optimization(&a);<br>
}<br>
<br>
template <class T><br>
@@ -1518,7 +1518,7 @@ void BinaryOpOriginTest(BinaryOp op) {<br>
// y is poisoned, x is not.<br>
*x = 10101;<br>
*y = *GetPoisonedO<T>(1, oy);<br>
- __msan_break_optimization(x);<br>
+ break_optimization(x);<br>
__msan_set_origin(z, sizeof(*z), 0);<br>
*z = op(*x, *y);<br>
EXPECT_POISONED_O(*z, oy);<br>
@@ -1527,7 +1527,7 @@ void BinaryOpOriginTest(BinaryOp op) {<br>
// x is poisoned, y is not.<br>
*x = *GetPoisonedO<T>(0, ox);<br>
*y = 10101010;<br>
- __msan_break_optimization(y);<br>
+ break_optimization(y);<br>
__msan_set_origin(z, sizeof(*z), 0);<br>
*z = op(*x, *y);<br>
EXPECT_POISONED_O(*z, ox);<br>
@@ -1645,7 +1645,7 @@ TEST(MemorySanitizerOrigins, Select) {<br>
EXPECT_NOT_POISONED(g_one ? 1 : *GetPoisonedO<S4>(0, __LINE__));<br>
EXPECT_POISONED_O(*GetPoisonedO<S4>(0, __LINE__), __LINE__);<br>
S4 x;<br>
- __msan_break_optimization(&x);<br>
+ break_optimization(&x);<br>
x = g_1 ? *GetPoisonedO<S4>(0, __LINE__) : 0;<br>
<br>
EXPECT_POISONED_O(g_1 ? *GetPoisonedO<S4>(0, __LINE__) : 1, __LINE__);<br>
@@ -1655,7 +1655,7 @@ TEST(MemorySanitizerOrigins, Select) {<br>
extern "C"<br>
NOINLINE char AllocaTO() {<br>
int ar[100];<br>
- __msan_break_optimization(ar);<br>
+ break_optimization(ar);<br>
return ar[10];<br>
// fprintf(stderr, "Descr: %s\n",<br>
// __msan_get_origin_descr_if_stack(__msan_get_origin_tls()));<br>
@@ -1677,7 +1677,7 @@ TEST(MemorySanitizerOrigins, DISABLED_Al<br>
<br>
NOINLINE int RetvalOriginTest(u32 origin) {<br>
int *a = new int;<br>
- __msan_break_optimization(a);<br>
+ break_optimization(a);<br>
__msan_set_origin(a, sizeof(*a), origin);<br>
int res = *a;<br>
delete a;<br>
@@ -1697,7 +1697,7 @@ TEST(MemorySanitizerOrigins, Param) {<br>
if (!TrackingOrigins()) return;<br>
int *a = new int;<br>
u32 origin = __LINE__;<br>
- __msan_break_optimization(a);<br>
+ break_optimization(a);<br>
__msan_set_origin(a, sizeof(*a), origin);<br>
ParamOriginTest(*a, origin);<br>
delete a;<br>
@@ -1711,7 +1711,7 @@ TEST(MemorySanitizerOrigins, Invoke) {<br>
<br>
TEST(MemorySanitizerOrigins, strlen) {<br>
S8 alignment;<br>
- __msan_break_optimization(&alignment);<br>
+ break_optimization(&alignment);<br>
char x[4] = {'a', 'b', 0, 0};<br>
__msan_poison(&x[2], 1);<br>
u32 origin = __LINE__;<br>
@@ -1745,8 +1745,8 @@ NOINLINE void RecursiveMalloc(int depth)<br>
printf("RecursiveMalloc: %d\n", count);<br>
int *x1 = new int;<br>
int *x2 = new int;<br>
- __msan_break_optimization(x1);<br>
- __msan_break_optimization(x2);<br>
+ break_optimization(x1);<br>
+ break_optimization(x2);<br>
if (depth > 0) {<br>
RecursiveMalloc(depth-1);<br>
RecursiveMalloc(depth-1);<br>
@@ -1768,7 +1768,6 @@ TEST(MemorySanitizerStress, DISABLED_Mal<br>
}<br>
<br>
int main(int argc, char **argv) {<br>
- __msan_set_poison_in_malloc(1);<br>
testing::InitGoogleTest(&argc, argv);<br>
int res = RUN_ALL_TESTS();<br>
return res;<br>
<br>
Modified: compiler-rt/trunk/lib/msan/tests/msandr_test_so.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/tests/msandr_test_so.cc?rev=173800&r1=173799&r2=173800&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/tests/msandr_test_so.cc?rev=173800&r1=173799&r2=173800&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/msan/tests/msandr_test_so.cc (original)<br>
+++ compiler-rt/trunk/lib/msan/tests/msandr_test_so.cc Tue Jan 29 08:33:29 2013<br>
@@ -34,3 +34,5 @@ int dso_stack_store(void (*fn)(int*, int<br>
fn(&x, &y);<br>
return y;<br>
}<br>
+<br>
+void break_optimization(void *x) {}<br>
<br>
Modified: compiler-rt/trunk/lib/msan/tests/msandr_test_so.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/tests/msandr_test_so.h?rev=173800&r1=173799&r2=173800&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/tests/msandr_test_so.h?rev=173800&r1=173799&r2=173800&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/msan/tests/msandr_test_so.h (original)<br>
+++ compiler-rt/trunk/lib/msan/tests/msandr_test_so.h Tue Jan 29 08:33:29 2013<br>
@@ -19,5 +19,6 @@ void dso_memfill(char* s, unsigned n);<br>
int dso_callfn(int (*fn)(void));<br>
int dso_callfn1(int (*fn)(long long, long long, long long)); //NOLINT<br>
int dso_stack_store(void (*fn)(int*, int*), int x);<br>
+void break_optimization(void *x);<br>
<br>
#endif<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>