Skip to content
This repository was archived by the owner on Jan 7, 2023. It is now read-only.

Commit c4a0345

Browse files
workaround for initialization order fiasco in llvm 7.0
For more information, see: 1. PR41367 (https://bugs.llvm.org/show_bug.cgi?id=41367) 2. llvm/llvm-project@c06a470#diff-a24105042657fab99820d2763969217c 3. llvm/llvm-project@46e5c5f#diff-a24105042657fab99820d2763969217c Change-Id: I984fa1da0b1718ae0b4ee0b9c601d1ab69203caf
1 parent 5005890 commit c4a0345

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Description : workaround for https://bugs.llvm.org/show_bug.cgi?id=41367
2+
# When Fixed in Open Source : Needed always
3+
# Category : Bugfix
4+
diff --git a/include/llvm/Support/ManagedStatic.h b/include/llvm/Support/ManagedStatic.h
5+
index b4bf321..3166d59 100644
6+
+++ b/include/llvm/Support/ManagedStatic.h
7+
--- a/include/llvm/Support/ManagedStatic.h
8+
@@ -17,6 +17,10 @@
9+
#include <atomic>
10+
#include <cstddef>
11+
12+
+#if !defined(_MSC_VER) || (_MSC_VER >= 1925) || defined(__clang__)
13+
+#define LLVM_USE_CONSTEXPR_CTOR
14+
+#endif
15+
+
16+
namespace llvm {
17+
18+
/// object_creator - Helper method for ManagedStatic.
19+
@@ -36,21 +40,33 @@ template <typename T, size_t N> struct object_deleter<T[N]> {
20+
/// ManagedStaticBase - Common base class for ManagedStatic instances.
21+
class ManagedStaticBase {
22+
protected:
23+
+#ifdef LLVM_USE_CONSTEXPR_CTOR
24+
+ mutable std::atomic<void *> Ptr{};
25+
+ mutable void (*DeleterFn)(void *) = nullptr;
26+
+ mutable const ManagedStaticBase *Next = nullptr;
27+
+#else
28+
// This should only be used as a static variable, which guarantees that this
29+
// will be zero initialized.
30+
mutable std::atomic<void *> Ptr;
31+
mutable void (*DeleterFn)(void*);
32+
mutable const ManagedStaticBase *Next;
33+
-
34+
+#endif
35+
void RegisterManagedStatic(void *(*creator)(), void (*deleter)(void*)) const;
36+
37+
public:
38+
+#ifdef LLVM_USE_CONSTEXPR_CTOR
39+
+ constexpr ManagedStaticBase() = default;
40+
+#endif
41+
/// isConstructed - Return true if this object has not been created yet.
42+
bool isConstructed() const { return Ptr != nullptr; }
43+
44+
void destroy() const;
45+
};
46+
47+
+// we don't need LLVM_USE_CONSTEXPR_CTOR anymore as it is used only to define
48+
+// a proper constructor and initializers
49+
+#undef LLVM_USE_CONSTEXPR_CTOR
50+
+
51+
/// ManagedStatic - This transparently changes the behavior of global statics to
52+
/// be lazily constructed on demand (good for reducing startup times of dynamic
53+
/// libraries that link in LLVM components) and for making destruction be

0 commit comments

Comments
 (0)