[compiler-rt] TSAN: Report when thread is not live and referenced in pthread (PR #156921)

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 4 10:21:10 PDT 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp,h -- compiler-rt/lib/sanitizer_common/sanitizer_thread_registry.cpp compiler-rt/lib/sanitizer_common/sanitizer_thread_registry.h compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp compiler-rt/lib/tsan/rtl/tsan_rtl.h compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cpp
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_thread_registry.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_thread_registry.cpp
index b8f32b52c..aaac2e852 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_thread_registry.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_thread_registry.cpp
@@ -276,7 +276,8 @@ void ThreadRegistry::JoinThread(u32 tid, void *arg) {
       ThreadContextBase *tctx = threads_[tid];
 
       if (!tctx) {
-        Report("%s: Tried to join thread %u, but it is not live.", SanitizerToolName, tid);
+        Report("%s: Tried to join thread %u, but it is not live.",
+               SanitizerToolName, tid);
       }
 
       CHECK_NE(tctx, 0);
@@ -362,7 +363,7 @@ ThreadContextBase *ThreadRegistry::QuarantinePop() {
   return tctx;
 }
 
-bool ThreadRegistry::ConsumeThreadUserId(uptr user_id, u32 *tid_out) {
+bool ThreadRegistry::ConsumeThreadUserId(uptr user_id, u32* tid_out) {
   ThreadRegistryLock l(this);
   auto *t = live_.find(user_id);
   if (!t) {
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_thread_registry.h b/compiler-rt/lib/sanitizer_common/sanitizer_thread_registry.h
index 83459685f..e4398f323 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_thread_registry.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_thread_registry.h
@@ -135,7 +135,7 @@ class SANITIZER_MUTEX ThreadRegistry {
   // Finishes thread and returns previous status.
   ThreadStatus FinishThread(u32 tid);
   void StartThread(u32 tid, ThreadID os_id, ThreadType thread_type, void *arg);
-  bool ConsumeThreadUserId(uptr user_id, u32 *tid_out);
+  bool ConsumeThreadUserId(uptr user_id, u32* tid_out);
   void SetThreadUserId(u32 tid, uptr user_id);
 
   // OnFork must be called in the child process after fork to purge old
diff --git a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
index 4eabea5ad..aa5f4e2d1 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
@@ -1132,7 +1132,10 @@ TSAN_INTERCEPTOR(int, pthread_join, void *th, void **ret) {
   SCOPED_INTERCEPTOR_RAW(pthread_join, th, ret);
   Tid tid;
   if (!ThreadConsumeTid(thr, pc, (uptr)th, &tid)) {
-    Report("ThreadSanitizer: pthread_join was called on thread %d but it is dead.\n", thr->tid);
+    Report(
+        "ThreadSanitizer: pthread_join was called on thread %d but it is "
+        "dead.\n",
+        thr->tid);
     return -errno_EINVAL;
   }
   ThreadIgnoreBegin(thr, pc);
@@ -1161,7 +1164,10 @@ TSAN_INTERCEPTOR(int, pthread_detach, void *th) {
   SCOPED_INTERCEPTOR_RAW(pthread_detach, th);
   Tid tid;
   if (!ThreadConsumeTid(thr, pc, (uptr)th, &tid)) {
-    Report("ThreadSanitizer: pthread_detach was called on thread %d but it is dead.\n", thr->tid);
+    Report(
+        "ThreadSanitizer: pthread_detach was called on thread %d but it is "
+        "dead.\n",
+        thr->tid);
     return -errno_EINVAL;
   }
   int res = REAL(pthread_detach)(th);
@@ -1186,7 +1192,10 @@ TSAN_INTERCEPTOR(int, pthread_tryjoin_np, void *th, void **ret) {
   SCOPED_INTERCEPTOR_RAW(pthread_tryjoin_np, th, ret);
   Tid tid;
   if (!ThreadConsumeTid(thr, pc, (uptr)th, &tid)) {
-    Report("ThreadSanitizer: pthread_tryjoin_np was called on thread %d but it is dead.\n", thr->tid);
+    Report(
+        "ThreadSanitizer: pthread_tryjoin_np was called on thread %d but it is "
+        "dead.\n",
+        thr->tid);
     return -errno_EINVAL;
   }
   ThreadIgnoreBegin(thr, pc);
@@ -1204,7 +1213,10 @@ TSAN_INTERCEPTOR(int, pthread_timedjoin_np, void *th, void **ret,
   SCOPED_INTERCEPTOR_RAW(pthread_timedjoin_np, th, ret, abstime);
   Tid tid;
   if (!ThreadConsumeTid(thr, pc, (uptr)th, &tid)) {
-    Report("ThreadSanitizer: pthread_timedjoin_np was called on thread %d but it is dead.\n", thr->tid);
+    Report(
+        "ThreadSanitizer: pthread_timedjoin_np was called on thread %d but it "
+        "is dead.\n",
+        thr->tid);
     return -errno_EINVAL;
   }
   ThreadIgnoreBegin(thr, pc);
diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl.h b/compiler-rt/lib/tsan/rtl/tsan_rtl.h
index 03bd4d8de..ea0b2c163 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_rtl.h
+++ b/compiler-rt/lib/tsan/rtl/tsan_rtl.h
@@ -563,7 +563,7 @@ Tid ThreadCreate(ThreadState *thr, uptr pc, uptr uid, bool detached);
 void ThreadStart(ThreadState *thr, Tid tid, ThreadID os_id,
                  ThreadType thread_type);
 void ThreadFinish(ThreadState *thr);
-bool ThreadConsumeTid(ThreadState *thr, uptr pc, uptr uid, Tid *tid_out);
+bool ThreadConsumeTid(ThreadState* thr, uptr pc, uptr uid, Tid* tid_out);
 void ThreadJoin(ThreadState *thr, uptr pc, Tid tid);
 void ThreadDetach(ThreadState *thr, uptr pc, Tid tid);
 void ThreadFinalize(ThreadState *thr);
diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cpp b/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cpp
index fd33dde7e..a8cb1d385 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cpp
@@ -301,7 +301,7 @@ struct ConsumeThreadContext {
   ThreadContextBase *tctx;
 };
 
-bool ThreadConsumeTid(ThreadState *thr, uptr pc, uptr uid, Tid *tid_out) {
+bool ThreadConsumeTid(ThreadState* thr, uptr pc, uptr uid, Tid* tid_out) {
   return ctx->thread_registry.ConsumeThreadUserId(uid, tid_out);
 }
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/156921


More information about the llvm-commits mailing list