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: target=powerpc64-unknown-linux-gnu{{.*}}
6#include "java.h"
7
8void foobar() {
9}
10
11void barbaz() {
12}
13
14void *Thread(void *p) {
15 barrier_wait(barrier: &barrier);
16 __tsan_read1_pc(addr: (jptr)p, pc: (jptr)foobar + kPCInc);
17 return 0;
18}
19
20int main() {
21 barrier_init(barrier: &barrier, count: 2);
22 int const kHeapSize = 1024 * 1024;
23 jptr jheap = (jptr)malloc(size: kHeapSize + 8) + 8;
24 __tsan_java_init(heap_begin: jheap, heap_size: kHeapSize);
25 const int kBlockSize = 16;
26 __tsan_java_alloc(ptr: jheap, size: kBlockSize);
27 pthread_t th;
28 pthread_create(newthread: &th, attr: 0, start_routine: Thread, arg: (void*)jheap);
29 __tsan_write1_pc(addr: (jptr)jheap, pc: (jptr)barbaz + kPCInc);
30 barrier_wait(barrier: &barrier);
31 pthread_join(th: th, thread_return: 0);
32 __tsan_java_free(ptr: jheap, size: kBlockSize);
33 fprintf(stderr, format: "DONE\n");
34 return __tsan_java_fini();
35}
36
37// CHECK: WARNING: ThreadSanitizer: data race
38// CHECK: #0 foobar
39// CHECK: #0 barbaz
40// CHECK: DONE
41

source code of compiler-rt/test/tsan/java_race_pc.cpp