[compiler-rt] r204240 - tsan: add test for second_deadlock_stack flag

Dmitry Vyukov dvyukov at google.com
Wed Mar 19 08:00:38 PDT 2014


Author: dvyukov
Date: Wed Mar 19 10:00:38 2014
New Revision: 204240

URL: http://llvm.org/viewvc/llvm-project?rev=204240&view=rev
Log:
tsan: add test for second_deadlock_stack flag


Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_deadlock_detector1.cc
    compiler-rt/trunk/lib/tsan/Makefile.old
    compiler-rt/trunk/lib/tsan/rtl/Makefile.old
    compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_mutex.cc
    compiler-rt/trunk/test/tsan/deadlock_detector_stress_test.cc

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_deadlock_detector1.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_deadlock_detector1.cc?rev=204240&r1=204239&r2=204240&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_deadlock_detector1.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_deadlock_detector1.cc Wed Mar 19 10:00:38 2014
@@ -36,8 +36,9 @@ struct DDLogicalThread {
 struct DD : public DDetector {
   SpinMutex mtx;
   DeadlockDetector<DDBV> dd;
+  DDFlags flags;
 
-  DD();
+  explicit DD(const DDFlags *flags);
 
   DDPhysicalThread* CreatePhysicalThread();
   void DestroyPhysicalThread(DDPhysicalThread *pt);
@@ -60,10 +61,11 @@ struct DD : public DDetector {
 DDetector *DDetector::Create(const DDFlags *flags) {
   (void)flags;
   void *mem = MmapOrDie(sizeof(DD), "deadlock detector");
-  return new(mem) DD();
+  return new(mem) DD(flags);
 }
 
-DD::DD() {
+DD::DD(const DDFlags *flags)
+    : flags(*flags) {
   dd.clear();
 }
 
@@ -135,14 +137,16 @@ void DD::ReportDeadlock(DDCallback *cb,
     rep->loop[i].thr_ctx = 0;  // don't know
     rep->loop[i].mtx_ctx0 = m0->ctx;
     rep->loop[i].mtx_ctx1 = m1->ctx;
-    rep->loop[i].stk[0] = stk_from;
-    rep->loop[i].stk[1] = stk_to;
+    rep->loop[i].stk[0] = stk_to;
+    rep->loop[i].stk[1] = stk_from;
   }
 }
 
 void DD::MutexAfterLock(DDCallback *cb, DDMutex *m, bool wlock, bool trylock) {
   DDLogicalThread *lt = cb->lt;
-  u32 stk = cb->Unwind();  // FIXME: if this is hot, do this under a flag.
+  u32 stk = 0;
+  if (flags.second_deadlock_stack)
+    stk = cb->Unwind();
   // Printf("T%p MutexLock:   %zx stk %u\n", lt, m->id, stk);
   if (dd.onFirstLock(&lt->dd, m->id, stk))
     return;

Modified: compiler-rt/trunk/lib/tsan/Makefile.old
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/Makefile.old?rev=204240&r1=204239&r2=204240&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/Makefile.old (original)
+++ compiler-rt/trunk/lib/tsan/Makefile.old Wed Mar 19 10:00:38 2014
@@ -1,6 +1,6 @@
 DEBUG=0
 LDFLAGS=-ldl -lpthread -pie
-CXXFLAGS = -fPIE -fno-rtti -g -Wall -Werror \
+CXXFLAGS = -std=c++11 -fPIE -fno-rtti -g -Wall -Werror \
 					 -DGTEST_HAS_RTTI=0 -DTSAN_DEBUG=$(DEBUG) -DSANITIZER_DEBUG=$(DEBUG)
 CLANG=clang
 FILECHECK=FileCheck

Modified: compiler-rt/trunk/lib/tsan/rtl/Makefile.old
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/Makefile.old?rev=204240&r1=204239&r2=204240&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/Makefile.old (original)
+++ compiler-rt/trunk/lib/tsan/rtl/Makefile.old Wed Mar 19 10:00:38 2014
@@ -1,4 +1,4 @@
-CXXFLAGS = -fPIE -g -Wall -Werror -fno-builtin -DTSAN_DEBUG=$(DEBUG) -DSANITIZER_DEBUG=$(DEBUG)
+CXXFLAGS = -std=c++11 -fPIE -g -Wall -Werror -fno-builtin -DTSAN_DEBUG=$(DEBUG) -DSANITIZER_DEBUG=$(DEBUG)
 CLANG=clang
 ifeq ($(DEBUG), 0)
   CXXFLAGS += -O3

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_mutex.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_mutex.cc?rev=204240&r1=204239&r2=204240&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_mutex.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_mutex.cc Wed Mar 19 10:00:38 2014
@@ -441,7 +441,7 @@ void ReportDeadlock(ThreadState *thr, up
   }
   // FIXME: use all stacks for suppressions, not just the second stack of the
   // first edge.
-  OutputReport(ctx, rep, rep.GetReport()->stacks[1]);
+  OutputReport(ctx, rep, rep.GetReport()->stacks[0]);
 }
 
 }  // namespace __tsan

Modified: compiler-rt/trunk/test/tsan/deadlock_detector_stress_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/deadlock_detector_stress_test.cc?rev=204240&r1=204239&r2=204240&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/deadlock_detector_stress_test.cc (original)
+++ compiler-rt/trunk/test/tsan/deadlock_detector_stress_test.cc Wed Mar 19 10:00:38 2014
@@ -1,5 +1,6 @@
 // RUN: %clangxx_tsan %s -o %t -DLockType=PthreadMutex
-// RUN: TSAN_OPTIONS=detect_deadlocks=1 not %t 2>&1 | FileCheck %s
+// RUN: TSAN_OPTIONS=detect_deadlocks=1 not %t 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NOT-SECOND
+// TSAN_OPTIONS="detect_deadlocks=1 second_deadlock_stack=1" not %t 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-SECOND
 // RUN: %clangxx_tsan %s -o %t -DLockType=PthreadSpinLock
 // RUN: TSAN_OPTIONS=detect_deadlocks=1 not %t 2>&1 | FileCheck %s
 // RUN: %clangxx_tsan %s -o %t -DLockType=PthreadRWLock
@@ -152,6 +153,14 @@ class LockTest {
     Lock_1_0();
     // CHECK: WARNING: ThreadSanitizer: lock-order-inversion (potential deadlock)
     // CHECK: Path: [[M1:M[0-9]+]] => [[M2:M[0-9]+]] => [[M1]]
+    // CHECK: Edge: [[M1]] => [[M2]]
+    // CHECK:   #0 pthread_
+    // CHECK-SECOND:   #0 pthread_
+    // CHECK-NOT-SECOND-NOT:   #0 pthread_
+    // CHECK: Edge: [[M2]] => [[M1]]
+    // CHECK:   #0 pthread_
+    // CHECK-SECOND:   #0 pthread_
+    // CHECK-NOT-SECOND-NOT:   #0 pthread_
     // CHECK: Mutex [[M1]] ([[A1]]) created at:
     // CHECK: Mutex [[M2]] ([[A2]]) created at:
     // CHECK-NOT: WARNING: ThreadSanitizer:
@@ -417,14 +426,14 @@ class LockTest {
     fprintf(stderr, "Starting Test16: detailed output test with two locks\n");
     // CHECK: Starting Test16
     // CHECK: WARNING: ThreadSanitizer: lock-order-inversion
-    // CHECK: LockTest::Acquire0
-    // CHECK-NEXT: LockTest::Acquire_0_then_1
     // CHECK: LockTest::Acquire1
     // CHECK-NEXT: LockTest::Acquire_0_then_1
-    // CHECK: LockTest::Acquire1
-    // CHECK-NEXT: LockTest::Acquire_1_then_0
+    // CHECK-SECOND: LockTest::Acquire0
+    // CHECK-SECOND-NEXT: LockTest::Acquire_0_then_1
     // CHECK: LockTest::Acquire0
     // CHECK-NEXT: LockTest::Acquire_1_then_0
+    // CHECK-SECOND: LockTest::Acquire1
+    // CHECK-SECOND-NEXT: LockTest::Acquire_1_then_0
     Init(5);
     Acquire_0_then_1();
     U(0); U(1);





More information about the llvm-commits mailing list