1// RUN: %clangxx_tsan %darwin_min_target_with_tls_support -O1 %s -o %t && \
2// RUN: %deflake %run %t | \
3// RUN: FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK
4#include "test.h"
5
6void *Thread2(void *a) {
7 barrier_wait(barrier: &barrier);
8 *(int*)a = 43;
9 return 0;
10}
11
12void *Thread(void *a) {
13 static __thread int Var = 42;
14 pthread_t t;
15 pthread_create(newthread: &t, attr: 0, start_routine: Thread2, arg: &Var);
16 Var = 42;
17 barrier_wait(barrier: &barrier);
18 pthread_join(th: t, thread_return: 0);
19 return 0;
20}
21
22int main() {
23 barrier_init(barrier: &barrier, count: 2);
24 pthread_t t;
25 pthread_create(newthread: &t, attr: 0, start_routine: Thread, arg: 0);
26 pthread_join(th: t, thread_return: 0);
27 fprintf(stderr, format: "DONE\n");
28 return 0;
29}
30
31// CHECK: WARNING: ThreadSanitizer: data race
32// CHECK-Linux: Location is TLS of thread T1.
33// CHECK-FreeBSD: Location is TLS of thread T1.
34// CHECK-NetBSD: Location is TLS of thread T1.
35// CHECK-Darwin: Location is heap block of size 4
36// CHECK: DONE
37

source code of compiler-rt/test/tsan/tls_race2.cpp