[PATCH] D29106: [tsan] Fix os_id of main thread
Phabricator via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 26 11:31:38 PST 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL293201: [tsan] Fix os_id of main thread (authored by kuba.brecka).
Changed prior to commit:
https://reviews.llvm.org/D29106?vs=85660&id=85944#toc
Repository:
rL LLVM
https://reviews.llvm.org/D29106
Files:
compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc
compiler-rt/trunk/test/tsan/Darwin/main_tid.mm
Index: compiler-rt/trunk/test/tsan/Darwin/main_tid.mm
===================================================================
--- compiler-rt/trunk/test/tsan/Darwin/main_tid.mm
+++ compiler-rt/trunk/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.
Index: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc
===================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc
@@ -381,7 +381,7 @@
// Initialize thread 0.
int tid = ThreadCreate(thr, 0, 0, true);
CHECK_EQ(tid, 0);
- ThreadStart(thr, tid, internal_getpid());
+ ThreadStart(thr, tid, GetTid());
#if TSAN_CONTAINS_UBSAN
__ubsan::InitAsPlugin();
#endif
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29106.85944.patch
Type: text/x-patch
Size: 2038 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170126/41608a2e/attachment.bin>
More information about the llvm-commits
mailing list