[llvm] Workaround -Wglobal-constructor warning. (PR #94699)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 6 16:38:17 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-support

Author: Eric Schweitz (schweitzpgi)

<details>
<summary>Changes</summary>

This line was tripping the -Wglobal-constructor warning which was causing a build failure when -Werror was turned on.

---
Full diff: https://github.com/llvm/llvm-project/pull/94699.diff


1 Files Affected:

- (modified) llvm/lib/Support/CodeGenCoverage.cpp (+5-2) 


``````````diff
diff --git a/llvm/lib/Support/CodeGenCoverage.cpp b/llvm/lib/Support/CodeGenCoverage.cpp
index 4d41c42e527e2..f87cbf18ef1a5 100644
--- a/llvm/lib/Support/CodeGenCoverage.cpp
+++ b/llvm/lib/Support/CodeGenCoverage.cpp
@@ -21,7 +21,10 @@
 
 using namespace llvm;
 
-static sys::SmartMutex<true> OutputMutex;
+static sys::SmartMutex<true> &OutputMutex() {
+  static sys::SmartMutex<true> mutex;
+  return mutex;
+}
 
 CodeGenCoverage::CodeGenCoverage() = default;
 
@@ -79,7 +82,7 @@ bool CodeGenCoverage::parse(MemoryBuffer &Buffer, StringRef BackendName) {
 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

``````````

</details>


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


More information about the llvm-commits mailing list