xref: /aosp_15_r20/external/compiler-rt/test/tsan/java_race_pc.cc (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
2*7c3d14c8STreehugger Robot // This test fails on powerpc64 big endian.
3*7c3d14c8STreehugger Robot // The Tsan report is returning wrong information about
4*7c3d14c8STreehugger Robot // the location of the race.
5*7c3d14c8STreehugger Robot // XFAIL: powerpc64-unknown-linux-gnu
6*7c3d14c8STreehugger Robot #include "java.h"
7*7c3d14c8STreehugger Robot 
foobar()8*7c3d14c8STreehugger Robot void foobar() {
9*7c3d14c8STreehugger Robot }
10*7c3d14c8STreehugger Robot 
barbaz()11*7c3d14c8STreehugger Robot void barbaz() {
12*7c3d14c8STreehugger Robot }
13*7c3d14c8STreehugger Robot 
Thread(void * p)14*7c3d14c8STreehugger Robot void *Thread(void *p) {
15*7c3d14c8STreehugger Robot   barrier_wait(&barrier);
16*7c3d14c8STreehugger Robot   __tsan_read1_pc((jptr)p, (jptr)foobar + kPCInc);
17*7c3d14c8STreehugger Robot   return 0;
18*7c3d14c8STreehugger Robot }
19*7c3d14c8STreehugger Robot 
main()20*7c3d14c8STreehugger Robot int main() {
21*7c3d14c8STreehugger Robot   barrier_init(&barrier, 2);
22*7c3d14c8STreehugger Robot   int const kHeapSize = 1024 * 1024;
23*7c3d14c8STreehugger Robot   jptr jheap = (jptr)malloc(kHeapSize + 8) + 8;
24*7c3d14c8STreehugger Robot   __tsan_java_init(jheap, kHeapSize);
25*7c3d14c8STreehugger Robot   const int kBlockSize = 16;
26*7c3d14c8STreehugger Robot   __tsan_java_alloc(jheap, kBlockSize);
27*7c3d14c8STreehugger Robot   pthread_t th;
28*7c3d14c8STreehugger Robot   pthread_create(&th, 0, Thread, (void*)jheap);
29*7c3d14c8STreehugger Robot   __tsan_write1_pc((jptr)jheap, (jptr)barbaz + kPCInc);
30*7c3d14c8STreehugger Robot   barrier_wait(&barrier);
31*7c3d14c8STreehugger Robot   pthread_join(th, 0);
32*7c3d14c8STreehugger Robot   __tsan_java_free(jheap, kBlockSize);
33*7c3d14c8STreehugger Robot   fprintf(stderr, "DONE\n");
34*7c3d14c8STreehugger Robot   return __tsan_java_fini();
35*7c3d14c8STreehugger Robot }
36*7c3d14c8STreehugger Robot 
37*7c3d14c8STreehugger Robot // CHECK: WARNING: ThreadSanitizer: data race
38*7c3d14c8STreehugger Robot // CHECK:     #0 foobar
39*7c3d14c8STreehugger Robot // CHECK:     #0 barbaz
40*7c3d14c8STreehugger Robot // CHECK: DONE
41