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