llvm-project
39 строк · 1.3 Кб
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
17int GlobalData[10];
18
19void *Thread(void *a) {
20barrier_wait(&barrier);
21GlobalData[2] = 42;
22return 0;
23}
24
25int main() {
26barrier_init(&barrier, 2);
27print_address("addr=", 1, GlobalData);
28pthread_t t;
29pthread_create(&t, 0, Thread, 0);
30GlobalData[2] = 43;
31barrier_wait(&barrier);
32pthread_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