[Mlir-commits] [mlir] fix a concurrent destruction issue for FallbackTypeIDResolver::registerImplicitTypeID due to function static variable (PR #85471)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Mar 15 14:43:19 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-core
Author: Li Deng (dengl11)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/85471.diff
1 Files Affected:
- (modified) mlir/lib/Support/TypeID.cpp (+5-2)
``````````diff
diff --git a/mlir/lib/Support/TypeID.cpp b/mlir/lib/Support/TypeID.cpp
index e499e2f2836334..0cf50bc2f721b7 100644
--- a/mlir/lib/Support/TypeID.cpp
+++ b/mlir/lib/Support/TypeID.cpp
@@ -81,8 +81,11 @@ struct ImplicitTypeIDRegistry {
} // end namespace
TypeID detail::FallbackTypeIDResolver::registerImplicitTypeID(StringRef name) {
- static ImplicitTypeIDRegistry registry;
- return registry.lookupOrInsert(name);
+ // To prevent race conditions when one thread is accessing this `static`
+ // variable while other threads are destructing it; construct the `registry`
+ // on the heap.
+ static auto *registry = new ImplicitTypeIDRegistry();
+ return registry->lookupOrInsert(name);
}
//===----------------------------------------------------------------------===//
``````````
</details>
https://github.com/llvm/llvm-project/pull/85471
More information about the Mlir-commits
mailing list