1 // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
2 // This test fails on powerpc64 big endian.
3 // The Tsan report is returning wrong information about
4 // the location of the race.
5 // XFAIL: powerpc64-unknown-linux-gnu
6 
7 #include "test.h"
8 
9 typedef unsigned long uptr;
10 extern "C" void __tsan_read_range_pc(uptr addr, uptr size, uptr pc);
11 extern "C" void __tsan_write_range_pc(uptr addr, uptr size, uptr pc);
12 
foobar()13 void foobar() {
14 }
15 
barbaz()16 void barbaz() {
17 }
18 
Thread(void * p)19 void *Thread(void *p) {
20   barrier_wait(&barrier);
21   __tsan_read_range_pc((uptr)p, 32, (uptr)foobar + kPCInc);
22   return 0;
23 }
24 
main()25 int main() {
26   barrier_init(&barrier, 2);
27   int a[128];
28   pthread_t th;
29   pthread_create(&th, 0, Thread, (void*)a);
30   __tsan_write_range_pc((uptr)(a+2), 32, (uptr)barbaz + kPCInc);
31   barrier_wait(&barrier);
32   pthread_join(th, 0);
33   fprintf(stderr, "DONE\n");
34   return 0;
35 }
36 
37 // CHECK: WARNING: ThreadSanitizer: data race
38 // CHECK:     #0 foobar
39 // CHECK:     #0 barbaz
40 // CHECK: DONE
41