diff options
author | Kuba Mracek <mracek@apple.com> | 2017-01-26 19:20:30 +0000 |
---|---|---|
committer | Kuba Mracek <mracek@apple.com> | 2017-01-26 19:20:30 +0000 |
commit | 85a6508b1dedce6bf4ff8ed1900291f7336c9f4e (patch) | |
tree | 246c12ef8419928f0813e4a010573766a4fc3fa4 /test/tsan/Darwin | |
parent | 07eeff5582edc11a4acbc516b18778f016c04723 (diff) | |
download | compiler-rt-85a6508b1dedce6bf4ff8ed1900291f7336c9f4e.tar.gz |
[tsan] Fix os_id of main thread
Currently, os_id of the main thread contains the PID instead of a thread ID. Let's fix this.
Differential Revision: https://reviews.llvm.org/D29106
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@293201 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/tsan/Darwin')
-rw-r--r-- | test/tsan/Darwin/main_tid.mm | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/test/tsan/Darwin/main_tid.mm b/test/tsan/Darwin/main_tid.mm new file mode 100644 index 000000000..af658e4b9 --- /dev/null +++ b/test/tsan/Darwin/main_tid.mm @@ -0,0 +1,46 @@ +// RUN: %clang_tsan %s -o %t -framework Foundation +// RUN: %deflake %run %t 2>&1 | FileCheck %s + +#import <pthread.h> +#import <stdio.h> +#import <stdlib.h> + +extern "C" { +void __tsan_on_report(void *report); +int __tsan_get_report_thread(void *report, unsigned long idx, int *tid, + unsigned long *os_id, int *running, + const char **name, int *parent_tid, void **trace, + unsigned long trace_size); +} + +void __tsan_on_report(void *report) { + fprintf(stderr, "__tsan_on_report(%p)\n", report); + + int tid; + unsigned long os_id; + int running; + const char *name; + int parent_tid; + void *trace[16] = {0}; + __tsan_get_report_thread(report, 0, &tid, &os_id, &running, &name, &parent_tid, trace, 16); + fprintf(stderr, "tid = %d, os_id = %lu\n", tid, os_id); +} + +int main() { + fprintf(stderr, "Hello world.\n"); + + uint64_t threadid; + pthread_threadid_np(NULL, &threadid); + fprintf(stderr, "pthread_threadid_np = %llu\n", threadid); + + pthread_mutex_t m; + pthread_mutex_init(&m, NULL); + pthread_mutex_unlock(&m); + fprintf(stderr, "Done.\n"); +} + +// CHECK: Hello world. +// CHECK: pthread_threadid_np = [[ADDR:[0-9]+]] +// CHECK: WARNING: ThreadSanitizer +// CHECK: tid = 0, os_id = [[ADDR]] +// CHECK: Done. |