summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/tsan/lit_tests
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2013-02-01 14:41:58 +0000
committerDmitry Vyukov <dvyukov@google.com>2013-02-01 14:41:58 +0000
commit87c6bb97162aaa9a9124f2af7dda411bac6f75fd (patch)
treee40feb4bd0da9c6e9c553bc44027d4654b364f2d /compiler-rt/lib/tsan/lit_tests
parent36a6dd04eff1956a5f638d9860c32d930cd4c194 (diff)
downloadbcm5719-llvm-87c6bb97162aaa9a9124f2af7dda411bac6f75fd.tar.gz
bcm5719-llvm-87c6bb97162aaa9a9124f2af7dda411bac6f75fd.zip
tsan: even if races between atomic and plain memory accesses are turned off (report_atomic_races=0),
still report races between atomic accesses and free(). llvm-svn: 174175
Diffstat (limited to 'compiler-rt/lib/tsan/lit_tests')
-rw-r--r--compiler-rt/lib/tsan/lit_tests/atomic_free.cc19
-rw-r--r--compiler-rt/lib/tsan/lit_tests/atomic_free2.cc19
-rw-r--r--compiler-rt/lib/tsan/lit_tests/race_on_mutex2.c24
3 files changed, 62 insertions, 0 deletions
diff --git a/compiler-rt/lib/tsan/lit_tests/atomic_free.cc b/compiler-rt/lib/tsan/lit_tests/atomic_free.cc
new file mode 100644
index 00000000000..ba9bd5ac4ae
--- /dev/null
+++ b/compiler-rt/lib/tsan/lit_tests/atomic_free.cc
@@ -0,0 +1,19 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
+#include <pthread.h>
+#include <unistd.h>
+
+void *Thread(void *a) {
+ __atomic_fetch_add((int*)a, 1, __ATOMIC_SEQ_CST);
+ return 0;
+}
+
+int main() {
+ int *a = new int(0);
+ pthread_t t;
+ pthread_create(&t, 0, Thread, a);
+ sleep(1);
+ delete a;
+ pthread_join(t, 0);
+}
+
+// CHECK: WARNING: ThreadSanitizer: data race
diff --git a/compiler-rt/lib/tsan/lit_tests/atomic_free2.cc b/compiler-rt/lib/tsan/lit_tests/atomic_free2.cc
new file mode 100644
index 00000000000..5517bf7ce90
--- /dev/null
+++ b/compiler-rt/lib/tsan/lit_tests/atomic_free2.cc
@@ -0,0 +1,19 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
+#include <pthread.h>
+#include <unistd.h>
+
+void *Thread(void *a) {
+ sleep(1);
+ __atomic_fetch_add((int*)a, 1, __ATOMIC_SEQ_CST);
+ return 0;
+}
+
+int main() {
+ int *a = new int(0);
+ pthread_t t;
+ pthread_create(&t, 0, Thread, a);
+ delete a;
+ pthread_join(t, 0);
+}
+
+// CHECK: WARNING: ThreadSanitizer: heap-use-after-free
diff --git a/compiler-rt/lib/tsan/lit_tests/race_on_mutex2.c b/compiler-rt/lib/tsan/lit_tests/race_on_mutex2.c
new file mode 100644
index 00000000000..84bef75a344
--- /dev/null
+++ b/compiler-rt/lib/tsan/lit_tests/race_on_mutex2.c
@@ -0,0 +1,24 @@
+// RUN: %clang_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
+#include <pthread.h>
+#include <stdio.h>
+#include <stddef.h>
+#include <unistd.h>
+
+void *Thread(void *x) {
+ pthread_mutex_lock((pthread_mutex_t*)x);
+ pthread_mutex_unlock((pthread_mutex_t*)x);
+ return 0;
+}
+
+int main() {
+ pthread_mutex_t Mtx;
+ pthread_mutex_init(&Mtx, 0);
+ pthread_t t;
+ pthread_create(&t, 0, Thread, &Mtx);
+ sleep(1);
+ pthread_mutex_destroy(&Mtx);
+ pthread_join(t, 0);
+ return 0;
+}
+
+// CHECK: WARNING: ThreadSanitizer: data race
OpenPOWER on IntegriCloud