[compiler-rt] r182354 - tsan: detect when a thread ends with ignores enabled

Dmitry Vyukov dvyukov at google.com
Tue May 21 01:12:36 PDT 2013


Author: dvyukov
Date: Tue May 21 03:12:35 2013
New Revision: 182354

URL: http://llvm.org/viewvc/llvm-project?rev=182354&view=rev
Log:
tsan: detect when a thread ends with ignores enabled

Added:
    compiler-rt/trunk/lib/tsan/lit_tests/thread_end_with_ignore.cc
    compiler-rt/trunk/lib/tsan/lit_tests/thread_end_with_ignore2.cc
Modified:
    compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_thread.cc

Added: compiler-rt/trunk/lib/tsan/lit_tests/thread_end_with_ignore.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/thread_end_with_ignore.cc?rev=182354&view=auto
==============================================================================
--- compiler-rt/trunk/lib/tsan/lit_tests/thread_end_with_ignore.cc (added)
+++ compiler-rt/trunk/lib/tsan/lit_tests/thread_end_with_ignore.cc Tue May 21 03:12:35 2013
@@ -0,0 +1,19 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
+#include <pthread.h>
+#include <stdio.h>
+
+extern "C" void AnnotateIgnoreReadsBegin(const char *f, int l);
+
+void *Thread(void *x) {
+  AnnotateIgnoreReadsBegin("", 0);
+  return 0;
+}
+
+int main() {
+  pthread_t t;
+  pthread_create(&t, 0, Thread, 0);
+  pthread_join(t, 0);
+}
+
+// CHECK: ThreadSanitizer: thread T1 finished with ignores enabled
+

Added: compiler-rt/trunk/lib/tsan/lit_tests/thread_end_with_ignore2.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/thread_end_with_ignore2.cc?rev=182354&view=auto
==============================================================================
--- compiler-rt/trunk/lib/tsan/lit_tests/thread_end_with_ignore2.cc (added)
+++ compiler-rt/trunk/lib/tsan/lit_tests/thread_end_with_ignore2.cc Tue May 21 03:12:35 2013
@@ -0,0 +1,9 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
+extern "C" void AnnotateIgnoreWritesBegin(const char *f, int l);
+
+int main() {
+  AnnotateIgnoreWritesBegin("", 0);
+}
+
+// CHECK: ThreadSanitizer: thread T0 finished with ignores enabled
+

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc?rev=182354&r1=182353&r2=182354&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc Tue May 21 03:12:35 2013
@@ -84,8 +84,7 @@ ThreadState::ThreadState(Context *ctx, i
   : fast_state(tid, epoch)
   // Do not touch these, rely on zero initialization,
   // they may be accessed before the ctor.
-  // , fast_ignore_reads()
-  // , fast_ignore_writes()
+  // , ignore_reads_and_writes()
   // , in_rtl()
   , shadow_stack_pos(&shadow_stack[0])
 #ifndef TSAN_GO

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_thread.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_thread.cc?rev=182354&r1=182353&r2=182354&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_thread.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_thread.cc Tue May 21 03:12:35 2013
@@ -165,8 +165,16 @@ static void MaybeReportThreadLeak(Thread
 }
 #endif
 
+static void ThreadCheckIgnore(ThreadState *thr) {
+  if (thr->ignore_reads_and_writes) {
+    Printf("ThreadSanitizer: thread T%d finished with ignores enabled.\n",
+           thr->tid);
+  }
+}
+
 void ThreadFinalize(ThreadState *thr) {
   CHECK_GT(thr->in_rtl, 0);
+  ThreadCheckIgnore(thr);
 #ifndef TSAN_GO
   if (!flags()->report_thread_leaks)
     return;
@@ -235,6 +243,7 @@ void ThreadStart(ThreadState *thr, int t
 
 void ThreadFinish(ThreadState *thr) {
   CHECK_GT(thr->in_rtl, 0);
+  ThreadCheckIgnore(thr);
   StatInc(thr, StatThreadFinish);
   if (thr->stk_addr && thr->stk_size)
     DontNeedShadowFor(thr->stk_addr, thr->stk_size);





More information about the llvm-commits mailing list