llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-codegen

Author: Wenju He (wenju-he)

<details>
<summary>Changes</summary>

When multiple threads launch multiple clang::CompilerInstance to compile 
sources, there is segfault and thread-sanitizer reports race condition in 
simultaneously writing to global variables llvm::TimePassesIsEnabled and 
llvm::TimePassesPerRun in BackendConsumer constructor.

This PR workarounds the issue by skipping the write when TimePasses is false. 
The actual values assigned to TimePassesIsEnabled and TimePassesPerRun are not 
changed.

Race condition still exists when TimePasses is true, but that is less common 
scenario.

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


1 Files Affected:

- (modified) clang/lib/CodeGen/CodeGenAction.cpp (+4-2) 


``````````diff
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index fb1a410ce1761..c7db71fdfc9f5 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -122,8 +122,10 @@ BackendConsumer::BackendConsumer(CompilerInstance &CI, 
BackendAction Action,
       Gen(CreateLLVMCodeGen(CI, InFile, C, CoverageInfo)),
       LinkModules(std::move(LinkModules)), CurLinkModule(CurLinkModule) {
   TimerIsEnabled = CodeGenOpts.TimePasses;
-  llvm::TimePassesIsEnabled = CodeGenOpts.TimePasses;
-  llvm::TimePassesPerRun = CodeGenOpts.TimePassesPerRun;
+  if (CodeGenOpts.TimePasses) {
+    llvm::TimePassesIsEnabled = true;
+    llvm::TimePassesPerRun = CodeGenOpts.TimePassesPerRun;
+  }
   if (CodeGenOpts.TimePasses)
     LLVMIRGeneration.init("irgen", "LLVM IR generation", CI.getTimerGroup());
 }

``````````

</details>


https://github.com/llvm/llvm-project/pull/200102
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to