[compiler-rt] r204035 - [sanitizer] fix build warnings; add an output test for the deadlock detecor

Kostya Serebryany kcc at google.com
Mon Mar 17 02:21:41 PDT 2014


Author: kcc
Date: Mon Mar 17 04:21:41 2014
New Revision: 204035

URL: http://llvm.org/viewvc/llvm-project?rev=204035&view=rev
Log:
[sanitizer] fix build warnings; add an output test for the deadlock detecor

Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_deadlock_detector_interface.h
    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_detector_interface.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_deadlock_detector_interface.h?rev=204035&r1=204034&r2=204035&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_deadlock_detector_interface.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_deadlock_detector_interface.h Mon Mar 17 04:21:41 2014
@@ -47,13 +47,14 @@ struct DDMutex {
 };
 
 struct DDReport {
+  enum { kMaxLoopSize = 16 };
   int n;  // number of entries in loop
   struct {
     u64 thr_ctx;   // user thread context
     u64 mtx_ctx0;  // user mutex context, start of the edge
     u64 mtx_ctx1;  // user mutex context, end of the edge
     u32 stk;       // stack id for the edge
-  } loop[16];
+  } loop[kMaxLoopSize];
 };
 
 struct DDCallback {

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=204035&r1=204034&r2=204035&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_mutex.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_mutex.cc Mon Mar 17 04:21:41 2014
@@ -426,7 +426,7 @@ void ReportDeadlock(ThreadState *thr, up
   ScopedReport rep(ReportTypeDeadlock);
   for (int i = 0; i < r->n; i++)
     rep.AddMutex(r->loop[i].mtx_ctx0);
-  StackTrace stacks[ARRAY_SIZE(DDReport::loop)];
+  StackTrace stacks[DDReport::kMaxLoopSize];
   for (int i = 0; i < r->n; i++) {
     if (!r->loop[i].stk) continue;
     uptr size;

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=204035&r1=204034&r2=204035&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/deadlock_detector_stress_test.cc (original)
+++ compiler-rt/trunk/test/tsan/deadlock_detector_stress_test.cc Mon Mar 17 04:21:41 2014
@@ -411,6 +411,34 @@ class LockTest {
     RL(0); RL(0); RL(0); RU(0); RU(0); RU(0);  // Recusrive reader lock.
   }
 
+  // More detailed output test.
+  void Test16() {
+    if (test_number > 0 && test_number != 16) return;
+    fprintf(stderr, "Starting Test16: detailed output test with two locks\n");
+    // CHECK: Starting Test16
+    // CHECK: WARNING: ThreadSanitizer: lock-order-inversion
+    // CHECK: LockTest::Acquire_1
+    // CHECK-NEXT: LockTest::Acquire_0_then_1
+    // CHECK: LockTest::Acquire_0
+    // CHECK-NEXT: LockTest::Acquire_1_then_0
+    Init(5);
+    Acquire_0_then_1();
+    U(0); U(1);
+    Acquire_1_then_0();
+    U(0); U(1);
+  }
+
+  __attribute__((noinline)) void Acquire_1() { L(1); }
+  __attribute__((noinline)) void Acquire_0() { L(0); }
+  __attribute__((noinline)) void Acquire_1_then_0() {
+    Acquire_1();
+    Acquire_0();
+  }
+  __attribute__((noinline)) void Acquire_0_then_1() {
+    Acquire_0();
+    Acquire_1();
+  }
+
  private:
   void Lock2(size_t l1, size_t l2) { L(l1); L(l2); U(l2); U(l1); }
   void Lock_0_1() { Lock2(0, 1); }
@@ -498,6 +526,7 @@ int main(int argc, char **argv) {
   LockTest().Test13();
   LockTest().Test14();
   LockTest().Test15();
+  LockTest().Test16();
   fprintf(stderr, "ALL-DONE\n");
   // CHECK: ALL-DONE
 }





More information about the llvm-commits mailing list