Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / java_symbolization_legacy.cpp
blob502d59def0891af64073b33bfe5f5ae7977b2cd2
1 // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
2 #include "java.h"
3 #include <memory.h>
4 #include <sanitizer/tsan_interface.h>
6 #if (__APPLE__)
7 __attribute__((weak)) // Required for dyld macOS 12.0+
8 #endif
9 __attribute__((disable_sanitizer_instrumentation))
10 extern "C" bool
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"));
16 *line = 1234;
17 *col = 56;
18 return true;
20 return false;
23 void *Thread(void *p) {
24 barrier_wait(&barrier);
25 __tsan_write1_pc((jptr)p, 1234 | kExternalPCBit);
26 return 0;
29 int main() {
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);
36 pthread_t th;
37 pthread_create(&th, 0, Thread, (void*)jheap);
38 __tsan_write1_pc((jptr)jheap, 1234 | kExternalPCBit);
39 barrier_wait(&barrier);
40 pthread_join(th, 0);
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
48 // CHECK: DONE