Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / global_race.cpp
blob66959827bb4092ea39b09efe2716fee861b2444e
1 // RUN: rm -rf %t-dir
2 // RUN: mkdir %t-dir
4 // RUN: %clangxx_tsan -O1 %s -o %t-dir/global_race.cpp.exe && %deflake %run %t-dir/global_race.cpp.exe 2>&1 \
5 // RUN: | FileCheck %s
7 // Also check that memory access instrumentation can be configured by either
8 // driver or legacy flags:
10 // RUN: %clangxx_tsan -O1 %s -o %t-dir/global_race.cpp.exe -fno-sanitize-thread-memory-access && not %deflake %run %t-dir/global_race.cpp.exe 2>&1 \
11 // RUN: | FileCheck --allow-empty --check-prefix=CHECK-MEMORY-ACCESS-OFF %s
12 // RUN: %clangxx_tsan -O1 %s -o %t-dir/global_race.cpp.exe -mllvm -tsan-instrument-memory-accesses=0 && not %deflake %run %t-dir/global_race.cpp.exe 2>&1 \
13 // RUN: | FileCheck --allow-empty --check-prefix=CHECK-MEMORY-ACCESS-OFF %s
15 #include "test.h"
17 int GlobalData[10];
19 void *Thread(void *a) {
20 barrier_wait(&barrier);
21 GlobalData[2] = 42;
22 return 0;
25 int main() {
26 barrier_init(&barrier, 2);
27 print_address("addr=", 1, GlobalData);
28 pthread_t t;
29 pthread_create(&t, 0, Thread, 0);
30 GlobalData[2] = 43;
31 barrier_wait(&barrier);
32 pthread_join(t, 0);
35 // CHECK: addr=[[ADDR:0x[0-9,a-f]+]]
36 // CHECK: WARNING: ThreadSanitizer: data race
37 // CHECK: Location is global 'GlobalData' {{(of size 40 )?}}at [[ADDR]] (global_race.cpp.exe+0x{{[0-9,a-f]+}})
39 // CHECK-MEMORY-ACCESS-OFF-NOT: WARNING: ThreadSanitizer: data race