1// RUN: %clang_tsan %s -o %t -framework Foundation 2// RUN: %deflake %run %t 2>&1 | FileCheck %s 3 4#import <pthread.h> 5#import <stdio.h> 6#import <stdlib.h> 7 8extern "C" { 9void __tsan_on_report(void *report); 10int __tsan_get_report_thread(void *report, unsigned long idx, int *tid, 11 uint64_t *os_id, int *running, 12 const char **name, int *parent_tid, void **trace, 13 unsigned long trace_size); 14} 15 16void __tsan_on_report(void *report) { 17 fprintf(stderr, "__tsan_on_report(%p)\n", report); 18 19 int tid; 20 uint64_t os_id; 21 int running; 22 const char *name; 23 int parent_tid; 24 void *trace[16] = {0}; 25 __tsan_get_report_thread(report, 0, &tid, &os_id, &running, &name, &parent_tid, trace, 16); 26 fprintf(stderr, "tid = %d, os_id = %lu\n", tid, os_id); 27} 28 29int main() { 30 fprintf(stderr, "Hello world.\n"); 31 32 uint64_t threadid; 33 pthread_threadid_np(NULL, &threadid); 34 fprintf(stderr, "pthread_threadid_np = %llu\n", threadid); 35 36 pthread_mutex_t m; 37 pthread_mutex_init(&m, NULL); 38 pthread_mutex_unlock(&m); 39 fprintf(stderr, "Done.\n"); 40} 41 42// CHECK: Hello world. 43// CHECK: pthread_threadid_np = [[ADDR:[0-9]+]] 44// CHECK: WARNING: ThreadSanitizer 45// CHECK: tid = 0, os_id = [[ADDR]] 46// CHECK: Done. 47