[compiler-rt] r331023 - tsan: improve "destroy of a locked mutex" reports
Dmitry Vyukov via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 27 01:59:35 PDT 2018
Author: dvyukov
Date: Fri Apr 27 01:59:35 2018
New Revision: 331023
URL: http://llvm.org/viewvc/llvm-project?rev=331023&view=rev
Log:
tsan: improve "destroy of a locked mutex" reports
1. Allow to suppress by current stack.
We generally allow to suppress by all main stacks.
Current is probably the stack one wants to use to
suppress such reports.
2. Fix last lock stack restoration.
We trimmed shadow value by storing it in u32.
This magically worked for the test that provoked
the report on the main thread. But this breaks
for locks in any other threads.
Added:
compiler-rt/trunk/test/tsan/mutex_destroy_locked2.cc
compiler-rt/trunk/test/tsan/suppressions_mutex.cc
compiler-rt/trunk/test/tsan/suppressions_mutex.cc.supp
Modified:
compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_mutex.cc
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=331023&r1=331022&r2=331023&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_mutex.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_mutex.cc Fri Apr 27 01:59:35 2018
@@ -104,7 +104,7 @@ void MutexDestroy(ThreadState *thr, uptr
unlock_locked = true;
}
u64 mid = s->GetId();
- u32 last_lock = s->last_lock;
+ u64 last_lock = s->last_lock;
if (!unlock_locked)
s->Reset(thr->proc()); // must not reset it before the report is printed
s->mtx.Unlock();
@@ -114,7 +114,7 @@ void MutexDestroy(ThreadState *thr, uptr
rep.AddMutex(mid);
VarSizeStackTrace trace;
ObtainCurrentStack(thr, pc, &trace);
- rep.AddStack(trace);
+ rep.AddStack(trace, true);
FastState last(last_lock);
RestoreStack(last.tid(), last.epoch(), &trace, 0);
rep.AddStack(trace, true);
Added: compiler-rt/trunk/test/tsan/mutex_destroy_locked2.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/mutex_destroy_locked2.cc?rev=331023&view=auto
==============================================================================
--- compiler-rt/trunk/test/tsan/mutex_destroy_locked2.cc (added)
+++ compiler-rt/trunk/test/tsan/mutex_destroy_locked2.cc Fri Apr 27 01:59:35 2018
@@ -0,0 +1,29 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
+#include <pthread.h>
+#include <unistd.h>
+
+void *thread(void *arg) {
+ pthread_mutex_t m;
+ pthread_mutex_init(&m, 0);
+ pthread_mutex_lock(&m);
+ pthread_mutex_destroy(&m);
+ return 0;
+}
+
+int main() {
+ pthread_t th;
+ pthread_create(&th, 0, thread, 0);
+ pthread_join(th, 0);
+ return 0;
+}
+
+// CHECK: WARNING: ThreadSanitizer: destroy of a locked mutex
+// CHECK: #0 pthread_mutex_destroy
+// CHECK: #1 thread
+// CHECK: and:
+// CHECK: #0 pthread_mutex_lock
+// CHECK: #1 thread
+// CHECK: Mutex {{.*}} created at:
+// CHECK: #0 pthread_mutex_init
+// CHECK: #1 thread
+// CHECK: SUMMARY: ThreadSanitizer: destroy of a locked mutex {{.*}} in thread
Added: compiler-rt/trunk/test/tsan/suppressions_mutex.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/suppressions_mutex.cc?rev=331023&view=auto
==============================================================================
--- compiler-rt/trunk/test/tsan/suppressions_mutex.cc (added)
+++ compiler-rt/trunk/test/tsan/suppressions_mutex.cc Fri Apr 27 01:59:35 2018
@@ -0,0 +1,19 @@
+// RUN: %clang_tsan -O1 %s -o %t && %env_tsan_opts=suppressions='%s.supp' %run %t 2>&1 | FileCheck %s
+#include "test.h"
+
+void __attribute__((noinline)) suppress_this(pthread_mutex_t *mu) {
+ pthread_mutex_destroy(mu);
+}
+
+int main() {
+ pthread_mutex_t mu;
+ pthread_mutex_init(&mu, 0);
+ pthread_mutex_lock(&mu);
+ suppress_this(&mu);
+ fprintf(stderr, "DONE\n");
+ return 0;
+}
+
+// CHECK-NOT: failed to open suppressions file
+// CHECK-NOT: WARNING: ThreadSanitizer:
+// CHECK: DONE
Added: compiler-rt/trunk/test/tsan/suppressions_mutex.cc.supp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/suppressions_mutex.cc.supp?rev=331023&view=auto
==============================================================================
--- compiler-rt/trunk/test/tsan/suppressions_mutex.cc.supp (added)
+++ compiler-rt/trunk/test/tsan/suppressions_mutex.cc.supp Fri Apr 27 01:59:35 2018
@@ -0,0 +1,2 @@
+mutex:suppress_this
+
More information about the llvm-commits
mailing list