2018-07-10 20:53:46 +08:00
|
|
|
// RUN: rm -rf %t-dir
|
|
|
|
// RUN: mkdir %t-dir
|
|
|
|
|
|
|
|
// RUN: %clangxx_tsan -O1 %s -o %t-dir/global_race.cc.exe && %deflake %run %t-dir/global_race.cc.exe 2>&1 \
|
2016-11-12 07:17:49 +08:00
|
|
|
// RUN: | FileCheck %s
|
|
|
|
|
|
|
|
// Also check that memory access instrumentation can be configured by either
|
|
|
|
// driver or legacy flags:
|
|
|
|
|
2018-07-10 20:53:46 +08:00
|
|
|
// RUN: %clangxx_tsan -O1 %s -o %t-dir/global_race.cc.exe -fno-sanitize-thread-memory-access && not %deflake %run %t-dir/global_race.cc.exe 2>&1 \
|
2016-11-12 07:17:49 +08:00
|
|
|
// RUN: | FileCheck --allow-empty --check-prefix=CHECK-MEMORY-ACCESS-OFF %s
|
2018-07-10 20:53:46 +08:00
|
|
|
// RUN: %clangxx_tsan -O1 %s -o %t-dir/global_race.cc.exe -mllvm -tsan-instrument-memory-accesses=0 && not %deflake %run %t-dir/global_race.cc.exe 2>&1 \
|
2016-11-12 07:17:49 +08:00
|
|
|
// RUN: | FileCheck --allow-empty --check-prefix=CHECK-MEMORY-ACCESS-OFF %s
|
|
|
|
|
2015-01-21 21:50:02 +08:00
|
|
|
#include "test.h"
|
2013-01-11 15:23:51 +08:00
|
|
|
|
|
|
|
int GlobalData[10];
|
|
|
|
|
|
|
|
void *Thread(void *a) {
|
2015-01-21 21:50:02 +08:00
|
|
|
barrier_wait(&barrier);
|
2013-01-11 15:23:51 +08:00
|
|
|
GlobalData[2] = 42;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
2015-01-21 21:50:02 +08:00
|
|
|
barrier_init(&barrier, 2);
|
2015-12-01 03:43:03 +08:00
|
|
|
print_address("addr=", 1, GlobalData);
|
2013-01-11 15:23:51 +08:00
|
|
|
pthread_t t;
|
|
|
|
pthread_create(&t, 0, Thread, 0);
|
|
|
|
GlobalData[2] = 43;
|
2015-01-21 21:50:02 +08:00
|
|
|
barrier_wait(&barrier);
|
2013-01-11 15:23:51 +08:00
|
|
|
pthread_join(t, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK: addr=[[ADDR:0x[0-9,a-f]+]]
|
2013-10-16 17:56:17 +08:00
|
|
|
// CHECK: WARNING: ThreadSanitizer: data race
|
2015-11-12 22:34:17 +08:00
|
|
|
// CHECK: Location is global 'GlobalData' {{(of size 40 )?}}at [[ADDR]] (global_race.cc.exe+0x{{[0-9,a-f]+}})
|
2014-05-30 22:08:51 +08:00
|
|
|
|
2016-11-12 07:17:49 +08:00
|
|
|
// CHECK-MEMORY-ACCESS-OFF-NOT: WARNING: ThreadSanitizer: data race
|