Index: compiler-rt/lib/sanitizer_common/sanitizer_common.h =================================================================== --- compiler-rt/lib/sanitizer_common/sanitizer_common.h +++ compiler-rt/lib/sanitizer_common/sanitizer_common.h @@ -213,6 +213,8 @@ public: explicit ScopedErrorReportLock(u32 current_tid); ~ScopedErrorReportLock(); + + static void CheckLocked(); }; extern uptr stoptheworld_tracer_pid; Index: compiler-rt/lib/sanitizer_common/sanitizer_common.cc =================================================================== --- compiler-rt/lib/sanitizer_common/sanitizer_common.cc +++ compiler-rt/lib/sanitizer_common/sanitizer_common.cc @@ -385,6 +385,10 @@ atomic_store_relaxed(&reporting_thread_tid, kUnclaimedTid); } +void ScopedErrorReportLock::CheckLocked() { + CommonSanitizerReportMutex.CheckLocked(); +} + } // namespace __sanitizer using namespace __sanitizer; // NOLINT Index: compiler-rt/lib/ubsan/ubsan_diag.h =================================================================== --- compiler-rt/lib/ubsan/ubsan_diag.h +++ compiler-rt/lib/ubsan/ubsan_diag.h @@ -239,6 +239,8 @@ /// report. This class ensures that reports from different threads and from /// different sanitizers won't be mixed. class ScopedReport { + ScopedErrorReportLock report_lock_; + ReportOptions Opts; Location SummaryLoc; ErrorType Type; @@ -246,6 +248,8 @@ public: ScopedReport(ReportOptions Opts, Location SummaryLoc, ErrorType Type); ~ScopedReport(); + + static void CheckLocked() { ScopedErrorReportLock::CheckLocked(); } }; void InitializeSuppressions(); Index: compiler-rt/lib/ubsan/ubsan_diag.cc =================================================================== --- compiler-rt/lib/ubsan/ubsan_diag.cc +++ compiler-rt/lib/ubsan/ubsan_diag.cc @@ -337,7 +337,7 @@ Diag::~Diag() { // All diagnostics should be printed under report mutex. - CommonSanitizerReportMutex.CheckLocked(); + ScopedReport::CheckLocked(); Decorator Decor; InternalScopedString Buffer(1024); @@ -365,17 +365,19 @@ PrintMemorySnippet(Decor, Loc.getMemoryLocation(), Ranges, NumRanges, Args); } -ScopedReport::ScopedReport(ReportOptions Opts, Location SummaryLoc, - ErrorType Type) - : Opts(Opts), SummaryLoc(SummaryLoc), Type(Type) { +static tid_t InitializeAndGetTid() { InitAsStandaloneIfNecessary(); - CommonSanitizerReportMutex.Lock(); + return GetTid(); } +ScopedReport::ScopedReport(ReportOptions Opts, Location SummaryLoc, + ErrorType Type) + : report_lock_(InitializeAndGetTid()), Opts(Opts), SummaryLoc(SummaryLoc), + Type(Type) {} + ScopedReport::~ScopedReport() { MaybePrintStackTrace(Opts.pc, Opts.bp); MaybeReportErrorSummary(SummaryLoc, Type); - CommonSanitizerReportMutex.Unlock(); if (flags()->halt_on_error) Die(); }