1 // RUN: %clangxx_tsan -O1 %s -o %t
2 // RUN: %deflake %run %t 2>&1 | FileCheck %s
12 void __tsan_on_report(void *report
);
13 int __tsan_get_report_loc(void *report
, unsigned long idx
, const char **type
,
14 void **addr
, void **start
,
15 unsigned long *size
, int *tid
, int *fd
,
16 int *suppressable
, void **trace
,
17 unsigned long trace_size
);
18 int __tsan_get_report_loc_object_type(void *report
, unsigned long idx
,
19 const char **object_type
);
22 void *Thread(void *arg
) {
23 barrier_wait(&barrier
);
29 barrier_init(&barrier
, 2);
30 void *tag
= __tsan_external_register_tag("MyObject");
31 long *obj
= (long *)malloc(sizeof(long));
32 fprintf(stderr
, "obj = %p\n", obj
);
33 // CHECK: obj = [[ADDR:0x[0-9a-f]+]]
34 __tsan_external_assign_tag(obj
, tag
);
37 pthread_create(&t
, 0, Thread
, obj
);
39 barrier_wait(&barrier
);
41 fprintf(stderr
, "Done.\n");
45 // Required for dyld macOS 12.0+
49 __attribute__((disable_sanitizer_instrumentation
))
51 __tsan_on_report(void *report
) {
56 int tid
, fd
, suppressable
;
57 void *trace
[16] = {0};
58 __tsan_get_report_loc(report
, 0, &type
, &addr
, &start
, &size
, &tid
, &fd
,
59 &suppressable
, trace
, 16);
60 fprintf(stderr
, "type = %s, start = %p, size = %ld\n", type
, start
, size
);
61 // CHECK: type = heap, start = [[ADDR]], size = 8
63 const char *object_type
;
64 __tsan_get_report_loc_object_type(report
, 0, &object_type
);
65 fprintf(stderr
, "object_type = %s\n", object_type
);
66 // CHECK: object_type = MyObject
70 // CHECK: ThreadSanitizer: reported 1 warnings