[PATCH] D38194: [ubsan] Replace CommonSanitizerReportMutex with ScopedErrorReportLock

Vitaly Buka via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 25 05:08:00 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL314053: [ubsan] Replace CommonSanitizerReportMutex with ScopedErrorReportLock (authored by vitalybuka).

Changed prior to commit:
  https://reviews.llvm.org/D38194?vs=116430&id=116532#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38194

Files:
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc
  compiler-rt/trunk/lib/ubsan/ubsan_diag.cc
  compiler-rt/trunk/lib/ubsan/ubsan_diag.h


Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
@@ -213,6 +213,8 @@
  public:
   ScopedErrorReportLock();
   ~ScopedErrorReportLock();
+
+  static void CheckLocked();
 };
 
 extern uptr stoptheworld_tracer_pid;
Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc
@@ -334,6 +334,10 @@
   atomic_store_relaxed(&reporting_thread, 0);
 }
 
+void ScopedErrorReportLock::CheckLocked() {
+  CommonSanitizerReportMutex.CheckLocked();
+}
+
 }  // namespace __sanitizer
 
 SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_sandbox_on_notify,
Index: compiler-rt/trunk/lib/ubsan/ubsan_diag.h
===================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_diag.h
+++ compiler-rt/trunk/lib/ubsan/ubsan_diag.h
@@ -239,13 +239,21 @@
 /// report. This class ensures that reports from different threads and from
 /// different sanitizers won't be mixed.
 class ScopedReport {
+  struct Initializer {
+    Initializer();
+  };
+  Initializer initializer_;
+  ScopedErrorReportLock report_lock_;
+
   ReportOptions Opts;
   Location SummaryLoc;
   ErrorType Type;
 
 public:
   ScopedReport(ReportOptions Opts, Location SummaryLoc, ErrorType Type);
   ~ScopedReport();
+
+  static void CheckLocked() { ScopedErrorReportLock::CheckLocked(); }
 };
 
 void InitializeSuppressions();
Index: compiler-rt/trunk/lib/ubsan/ubsan_diag.cc
===================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_diag.cc
+++ compiler-rt/trunk/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,15 @@
     PrintMemorySnippet(Decor, Loc.getMemoryLocation(), Ranges, NumRanges, Args);
 }
 
+ScopedReport::Initializer::Initializer() { InitAsStandaloneIfNecessary(); }
+
 ScopedReport::ScopedReport(ReportOptions Opts, Location SummaryLoc,
                            ErrorType Type)
-    : Opts(Opts), SummaryLoc(SummaryLoc), Type(Type) {
-  InitAsStandaloneIfNecessary();
-  CommonSanitizerReportMutex.Lock();
-}
+    : Opts(Opts), SummaryLoc(SummaryLoc), Type(Type) {}
 
 ScopedReport::~ScopedReport() {
   MaybePrintStackTrace(Opts.pc, Opts.bp);
   MaybeReportErrorSummary(SummaryLoc, Type);
-  CommonSanitizerReportMutex.Unlock();
   if (flags()->halt_on_error)
     Die();
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38194.116532.patch
Type: text/x-patch
Size: 2885 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170925/34a3666f/attachment.bin>


More information about the llvm-commits mailing list