llvm-project
77 строк · 2.8 Кб
1// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
2
3#include "test.h"4
5extern "C" {6void __tsan_on_report(void *report);7void *__tsan_get_current_report();8int __tsan_get_report_data(void *report, const char **description, int *count,9int *stack_count, int *mop_count, int *loc_count,10int *mutex_count, int *thread_count,11int *unique_tid_count, void **sleep_trace,12unsigned long trace_size);13int __tsan_get_report_stack(void *report, unsigned long idx, void **trace,14unsigned long trace_size);15int __tsan_get_report_mutex(void *report, unsigned long idx, uint64_t *mutex_id,16void **addr, int *destroyed, void **trace,17unsigned long trace_size);18}
19
20int main() {21int m = 0;22fprintf(stderr, "&m = %p\n", &m);23// CHECK: &m = [[MUTEX:0x[0-9a-f]+]]24AnnotateRWLockReleased(__FILE__, __LINE__, &m, 1);25fprintf(stderr, "Done.\n");26return 0;27}
28
29// Required for dyld macOS 12.0+
30#if (__APPLE__)31__attribute__((weak))32#endif33__attribute__((disable_sanitizer_instrumentation)) extern "C" void34__tsan_on_report(void *report) {35fprintf(stderr, "__tsan_on_report(%p)\n", report);36fprintf(stderr, "__tsan_get_current_report() = %p\n",37__tsan_get_current_report());38// CHECK: __tsan_on_report([[REPORT:0x[0-9a-f]+]])39// CHECK: __tsan_get_current_report() = [[REPORT]]40
41const char *description;42int count;43int stack_count, mop_count, loc_count, mutex_count, thread_count,44unique_tid_count;45void *sleep_trace[16] = {0};46__tsan_get_report_data(report, &description, &count, &stack_count, &mop_count,47&loc_count, &mutex_count, &thread_count,48&unique_tid_count, sleep_trace, 16);49
50fprintf(stderr, "stack_count = %d\n", stack_count);51// CHECK: stack_count = 152
53fprintf(stderr, "mutex_count = %d\n", mutex_count);54// CHECK: mutex_count = 155
56void *trace[16] = {0};57__tsan_get_report_stack(report, 0, trace, 16);58
59fprintf(stderr, "trace[0] = %p, trace[1] = %p, trace[2] = %p\n", trace[0],60trace[1], trace[2]);61// CHECK: trace[0] = 0x{{[0-9a-f]+}}, trace[1] = 0x{{[0-9a-f]+}}, trace[2] =62// {{0x0|\(nil\)|\(null\)}}63
64uint64_t mutex_id;65void *addr;66int destroyed;67__tsan_get_report_mutex(report, 0, &mutex_id, &addr, &destroyed, trace, 16);68fprintf(stderr, "addr = %p, destroyed = %d\n", addr, destroyed);69// CHECK: addr = [[MUTEX]], destroyed = 070fprintf(stderr, "trace[0] = %p, trace[1] = %p, trace[2] = %p\n", trace[0],71trace[1], trace[2]);72// CHECK: trace[0] = 0x{{[0-9a-f]+}}, trace[1] = 0x{{[0-9a-f]+}}, trace[2] =73// {{0x0|\(nil\)|\(null\)}}74}
75
76// CHECK: Done.
77// CHECK: ThreadSanitizer: reported 1 warnings
78