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 
Thread(void * a)13 void *Thread(void *a) {
14   __atomic_fetch_add((int*)a, 1, __ATOMIC_SEQ_CST);
15   barrier_wait(&barrier);
16   return 0;
17 }
18 
main()19 int main() {
20   barrier_init(&barrier, 2);
21   int *a = new int(0);
22   pthread_t t;
23   pthread_create(&t, 0, Thread, a);
24   barrier_wait(&barrier);
25   delete a;
26   pthread_join(t, 0);
27 }
28 
29 // CHECK: WARNING: ThreadSanitizer: data race
30 
31 // CHECK-NO-ATOMICS-NOT: WARNING: ThreadSanitizer: data race
32