1 // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
4 #include <sanitizer/tsan_interface.h>
7 __attribute__((weak
)) // Required for dyld macOS 12.0+
9 __attribute__((disable_sanitizer_instrumentation
))
11 __tsan_symbolize_external(jptr pc
, char *func_buf
, jptr func_siz
,
12 char *file_buf
, jptr file_siz
, int *line
, int *col
) {
13 if (pc
== (1234 | kExternalPCBit
)) {
14 memcpy(func_buf
, "MyFunc", sizeof("MyFunc"));
15 memcpy(file_buf
, "MyFile.java", sizeof("MyFile.java"));
23 void *Thread(void *p
) {
24 barrier_wait(&barrier
);
25 __tsan_write1_pc((jptr
)p
, 1234 | kExternalPCBit
);
30 barrier_init(&barrier
, 2);
31 int const kHeapSize
= 1024 * 1024;
32 jptr jheap
= (jptr
)malloc(kHeapSize
+ 8) + 8;
33 __tsan_java_init(jheap
, kHeapSize
);
34 const int kBlockSize
= 16;
35 __tsan_java_alloc(jheap
, kBlockSize
);
37 pthread_create(&th
, 0, Thread
, (void*)jheap
);
38 __tsan_write1_pc((jptr
)jheap
, 1234 | kExternalPCBit
);
39 barrier_wait(&barrier
);
41 __tsan_java_free(jheap
, kBlockSize
);
42 fprintf(stderr
, "DONE\n");
43 return __tsan_java_fini();
46 // CHECK: WARNING: ThreadSanitizer: data race
47 // CHECK: #0 MyFunc MyFile.java:1234:56