summaryrefslogtreecommitdiff
path: root/test/tsan/tls_race.cc
diff options
context:
space:
mode:
Diffstat (limited to 'test/tsan/tls_race.cc')
-rw-r--r--test/tsan/tls_race.cc21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/tsan/tls_race.cc b/test/tsan/tls_race.cc
new file mode 100644
index 0000000000000..18589347e8063
--- /dev/null
+++ b/test/tsan/tls_race.cc
@@ -0,0 +1,21 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
+#include <pthread.h>
+#include <stddef.h>
+#include <unistd.h>
+
+void *Thread(void *a) {
+ sleep(1);
+ *(int*)a = 43;
+ return 0;
+}
+
+int main() {
+ static __thread int Var = 42;
+ pthread_t t;
+ pthread_create(&t, 0, Thread, &Var);
+ Var = 43;
+ pthread_join(t, 0);
+}
+
+// CHECK: WARNING: ThreadSanitizer: data race
+// CHECK: Location is TLS of main thread.