|
| 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