From fe856110aa71fa0d10972793a9b0af3c171aec30 Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Mon, 14 Nov 2011 20:50:16 +0000 Subject: Add support for tsan annotations (thread sanitizer, a valgrind-based tool). These annotations are disabled entirely when either ENABLE_THREADS is off, or building a release build. When enabled, they add calls to functions with no statements to ManagedStatic's getters. Use these annotations to inform tsan that the race used inside ManagedStatic initialization is actually benign. Thanks to Kostya Serebryany for helping write this patch! llvm-svn: 144567 --- llvm/lib/Support/ManagedStatic.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'llvm/lib/Support/ManagedStatic.cpp') diff --git a/llvm/lib/Support/ManagedStatic.cpp b/llvm/lib/Support/ManagedStatic.cpp index c767c15e71c..098cccb68df 100644 --- a/llvm/lib/Support/ManagedStatic.cpp +++ b/llvm/lib/Support/ManagedStatic.cpp @@ -27,8 +27,15 @@ void ManagedStaticBase::RegisterManagedStatic(void *(*Creator)(), if (Ptr == 0) { void* tmp = Creator ? Creator() : 0; + TsanHappensBefore(this); sys::MemoryFence(); + + // This write is racy against the first read in the ManagedStatic + // accessors. The race is benign because it does a second read after a + // memory fence, at which point it isn't possible to get a partial value. + TsanIgnoreWritesBegin(); Ptr = tmp; + TsanIgnoreWritesEnd(); DeleterFn = Deleter; // Add to list of managed statics. @@ -72,4 +79,3 @@ void llvm::llvm_shutdown() { if (llvm_is_multithreaded()) llvm_stop_multithreaded(); } - -- cgit v1.2.3