1 // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
6 __attribute__((weak
)) // Required for dyld macOS 12.0+
8 __attribute__((disable_sanitizer_instrumentation
))
10 __tsan_symbolize_external_ex(jptr pc
,
11 void (*add_frame
)(void *, const char *,
12 const char *, int, int),
14 if (pc
== (1234 | kExternalPCBit
)) {
15 add_frame(ctx
, "MyInnerFunc", "MyInnerFile.java", 1234, 56);
16 add_frame(ctx
, "MyOuterFunc", "MyOuterFile.java", 4321, 65);
18 if (pc
== (2345 | kExternalPCBit
)) {
19 add_frame(ctx
, "Caller1", "CallerFile.java", 111, 22);
20 add_frame(ctx
, "Caller2", "CallerFile.java", 333, 44);
22 if (pc
== (3456 | kExternalPCBit
)) {
23 add_frame(ctx
, "Allocer1", "Alloc.java", 11, 222);
24 add_frame(ctx
, "Allocer2", "Alloc.java", 33, 444);
28 void *Thread(void *p
) {
29 barrier_wait(&barrier
);
30 __tsan_func_entry(2345 | kExternalPCBit
);
31 __tsan_write1_pc((jptr
)p
+ 16, 1234 | kExternalPCBit
);
36 jptr
const kHeapSize
= 64 * 1024;
37 jptr java_heap
[kHeapSize
];
40 barrier_init(&barrier
, 2);
41 jptr jheap
= (jptr
)java_heap
;
42 __tsan_java_init(jheap
, kHeapSize
);
43 const int kBlockSize
= 32;
44 __tsan_func_entry(3456 | kExternalPCBit
);
45 __tsan_java_alloc(jheap
, kBlockSize
);
46 print_address("addr:", 2, jheap
, jheap
+ 16);
49 pthread_create(&th
, 0, Thread
, (void*)jheap
);
50 __tsan_func_entry(2345 | kExternalPCBit
);
51 __tsan_write1_pc(jheap
+ 16, 1234 | kExternalPCBit
);
53 barrier_wait(&barrier
);
55 __tsan_java_free(jheap
, kBlockSize
);
56 fprintf(stderr
, "DONE\n");
57 return __tsan_java_fini();
60 // CHECK: addr:[[BLOCK:0x[0-9,a-f]+]] [[ADDR:0x[0-9,a-f]+]]
61 // CHECK: WARNING: ThreadSanitizer: data race
62 // CHECK: Write of size 1 at [[ADDR]] by thread T1:
63 // CHECK: #0 MyInnerFunc MyInnerFile.java:1234:56
64 // CHECK: #1 MyOuterFunc MyOuterFile.java:4321:65
65 // CHECK: #2 Caller1 CallerFile.java:111:22
66 // CHECK: #3 Caller2 CallerFile.java:333:44
67 // CHECK: Previous write of size 1 at [[ADDR]] by main thread:
68 // CHECK: #0 MyInnerFunc MyInnerFile.java:1234:56
69 // CHECK: #1 MyOuterFunc MyOuterFile.java:4321:65
70 // CHECK: #2 Caller1 CallerFile.java:111:22
71 // CHECK: #3 Caller2 CallerFile.java:333:44
72 // CHECK: Location is heap block of size 32 at [[BLOCK]] allocated by main thread:
73 // CHECK: #0 Allocer1 Alloc.java:11:222
74 // CHECK: #1 Allocer2 Alloc.java:33:444