[PATCH] D111604: [Support] lazy initialize OutputMutex in CodeGenCoverage

Yuanfang Chen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 11 23:42:23 PDT 2021


ychen created this revision.
ychen added reviewers: mehdi_amini, dsanders.
Herald added subscribers: dexonsmith, hiraditya.
ychen requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

It seems this is desired for libSupport otherwize it trips
'-Werror=global-constructors'.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D111604

Files:
  llvm/lib/Support/CodeGenCoverage.cpp


Index: llvm/lib/Support/CodeGenCoverage.cpp
===================================================================
--- llvm/lib/Support/CodeGenCoverage.cpp
+++ llvm/lib/Support/CodeGenCoverage.cpp
@@ -13,6 +13,7 @@
 
 #include "llvm/Support/Endian.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Mutex.h"
 #include "llvm/Support/Process.h"
@@ -21,7 +22,7 @@
 
 using namespace llvm;
 
-static sys::SmartMutex<true> OutputMutex;
+static ManagedStatic<sys::SmartMutex<true>> OutputMutex;
 
 CodeGenCoverage::CodeGenCoverage() {}
 
@@ -78,7 +79,7 @@
 bool CodeGenCoverage::emit(StringRef CoveragePrefix,
                            StringRef BackendName) const {
   if (!CoveragePrefix.empty() && !RuleCoverage.empty()) {
-    sys::SmartScopedLock<true> Lock(OutputMutex);
+    sys::SmartScopedLock<true> Lock(*OutputMutex);
 
     // We can handle locking within a process easily enough but we don't want to
     // manage it between multiple processes. Use the process ID to ensure no


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111604.378888.patch
Type: text/x-patch
Size: 1079 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211012/d4019870/attachment.bin>


More information about the llvm-commits mailing list