https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/228643
>From 1d4a90f0ae1d2d3cfb33f554195aef6008bc10e6 Mon Sep 17 00:00:00 2001 From: Vitaly Buka <[email protected]> Date: Fri, 2 Oct 2026 20:06:49 -0700 Subject: [PATCH 1/2] [NFC][TSan] Move RestoreStack before ScopedReport in ReportDestroyLocked Run RestoreStack in its own lock scope before constructing ScopedReport in ReportDestroyLocked (matching ReportRace). This avoids acquiring ScopedErrorReportLock or symbolizing the current stack if RestoreStack fails, and avoids holding slot_lock and slot_mtx while populating the ScopedReport. Assisted-by: Gemini Pull Request: https://github.com/llvm/llvm-project/pull/228643 --- compiler-rt/lib/tsan/rtl/tsan_rtl_mutex.cpp | 23 +++++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl_mutex.cpp b/compiler-rt/lib/tsan/rtl/tsan_rtl_mutex.cpp index ea9260a9486b9..013c1d471ff2e 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl_mutex.cpp +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl_mutex.cpp @@ -563,27 +563,32 @@ void ReportDeadlock(ThreadState *thr, uptr pc, DDReport *r) { void ReportDestroyLocked(ThreadState *thr, uptr pc, uptr addr, FastState last_lock, StackID creation_stack_id) { - ScopedReport rep(ReportTypeMutexDestroyLocked); - // Release locks before symbolizing and outputting the report to avoid - // deadlocks. + VarSizeStackTrace last_lock_stack; { // We need to lock the slot during RestoreStack because it protects // the slot journal. Lock slot_lock(&ctx->slots[static_cast<uptr>(last_lock.sid())].mtx); ThreadRegistryLock l0(&ctx->thread_registry); Lock slots_lock(&ctx->slot_mtx); - rep.AddMutex(addr, creation_stack_id); - VarSizeStackTrace trace; - ObtainCurrentStack(thr, pc, &trace); - rep.AddStack(trace, true); - Tid tid; DynamicMutexSet mset; uptr tag; if (!RestoreStack(EventType::kLock, last_lock.sid(), last_lock.epoch(), - addr, 0, kAccessWrite, &tid, &trace, mset, &tag)) + addr, 0, kAccessWrite, &tid, &last_lock_stack, mset, + &tag)) return; + } + + ScopedReport rep(ReportTypeMutexDestroyLocked); + // Release locks before symbolizing and outputting the report to avoid + // deadlocks. + { + ThreadRegistryLock l0(&ctx->thread_registry); + rep.AddMutex(addr, creation_stack_id); + VarSizeStackTrace trace; + ObtainCurrentStack(thr, pc, &trace); rep.AddStack(trace, true); + rep.AddStack(last_lock_stack, true); rep.AddLocation(addr, 1); } OutputReport(thr, rep); >From d95b897b4bd2481d518332640fd4c42ea694f160 Mon Sep 17 00:00:00 2001 From: Vitaly Buka <[email protected]> Date: Sat, 3 Oct 2026 18:00:32 -0700 Subject: [PATCH 2/2] Move ObtainCurrentStack between locked blocks in #228643 Created using spr 1.3.7 --- compiler-rt/lib/tsan/rtl/tsan_rtl_mutex.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl_mutex.cpp b/compiler-rt/lib/tsan/rtl/tsan_rtl_mutex.cpp index 013c1d471ff2e..47dd013b7bf86 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl_mutex.cpp +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl_mutex.cpp @@ -579,14 +579,15 @@ void ReportDestroyLocked(ThreadState *thr, uptr pc, uptr addr, return; } + VarSizeStackTrace trace; + ObtainCurrentStack(thr, pc, &trace); + ScopedReport rep(ReportTypeMutexDestroyLocked); // Release locks before symbolizing and outputting the report to avoid // deadlocks. { ThreadRegistryLock l0(&ctx->thread_registry); rep.AddMutex(addr, creation_stack_id); - VarSizeStackTrace trace; - ObtainCurrentStack(thr, pc, &trace); rep.AddStack(trace, true); rep.AddStack(last_lock_stack, true); rep.AddLocation(addr, 1); _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
