1 // RUN: rm -rf %t-dir 2 // RUN: mkdir %t-dir 3 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 6 7 // Also check that memory access instrumentation can be configured by either 8 // driver or legacy flags: 9 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 14 15 #include "test.h" 16 17 int GlobalData[10]; 18 Thread(void * a)19void *Thread(void *a) { 20 barrier_wait(&barrier); 21 GlobalData[2] = 42; 22 return 0; 23 } 24 main()25int 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); 33 } 34 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]+}}) 38 39 // CHECK-MEMORY-ACCESS-OFF-NOT: WARNING: ThreadSanitizer: data race 40