summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2018-04-27 08:59:35 +0000
committerDmitry Vyukov <dvyukov@google.com>2018-04-27 08:59:35 +0000
commite27398661ef8ea118124519a2f97ec345fcc2d6a (patch)
tree868398611e8dfd1b846b8ea467921d8c4a382aa4 /test
parentb820ab28d0a40f7719fcaa3f94e824d4c84b55a0 (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@331023 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r--test/tsan/mutex_destroy_locked2.cc29
-rw-r--r--test/tsan/suppressions_mutex.cc19
-rw-r--r--test/tsan/suppressions_mutex.cc.supp2
3 files changed, 50 insertions, 0 deletions
diff --git a/test/tsan/mutex_destroy_locked2.cc b/test/tsan/mutex_destroy_locked2.cc
new file mode 100644
index 000000000..e29c96138
--- /dev/null
+++ b/test/tsan/mutex_destroy_locked2.cc
@@ -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
diff --git a/test/tsan/suppressions_mutex.cc b/test/tsan/suppressions_mutex.cc
new file mode 100644
index 000000000..5d3a5d052
--- /dev/null
+++ b/test/tsan/suppressions_mutex.cc
@@ -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
diff --git a/test/tsan/suppressions_mutex.cc.supp b/test/tsan/suppressions_mutex.cc.supp
new file mode 100644
index 000000000..595febbea
--- /dev/null
+++ b/test/tsan/suppressions_mutex.cc.supp
@@ -0,0 +1,2 @@
+mutex:suppress_this
+