1// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t 2>&1 | FileCheck %s
2
3// Also check that atomics instrumentation can be configured by either driver or
4// legacy flags:
5
6// RUN: %clangxx_tsan -O1 %s -o %t -fno-sanitize-thread-atomics && not %deflake %run %t 2>&1 \
7// RUN: | FileCheck --allow-empty --check-prefix=CHECK-NO-ATOMICS %s
8// RUN: %clangxx_tsan -O1 %s -o %t -mllvm -tsan-instrument-atomics=0 && not %deflake %run %t 2>&1 \
9// RUN: | FileCheck --allow-empty --check-prefix=CHECK-NO-ATOMICS %s <%t
10
11#include "test.h"
12
13void *Thread(void *a) {
14 __atomic_fetch_add((int*)a, 1, __ATOMIC_SEQ_CST);
15 barrier_wait(barrier: &barrier);
16 return 0;
17}
18
19int main() {
20 barrier_init(barrier: &barrier, count: 2);
21 int *a = new int(0);
22 pthread_t t;
23 pthread_create(newthread: &t, attr: 0, start_routine: Thread, arg: a);
24 barrier_wait(barrier: &barrier);
25 delete a;
26 pthread_join(th: t, thread_return: 0);
27}
28
29// CHECK: WARNING: ThreadSanitizer: data race
30
31// CHECK-NO-ATOMICS-NOT: WARNING: ThreadSanitizer: data race
32

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