Fix crash during llvm_shutdown due to init order fiasco

Use the constexpr constructor for _MSC_VER >= 1925, otherwise ManagedStatic will have a dynamic initializer, which depending on init order, results in the Ptr field being overwritten with 0. This eventually leads to multiple instances of the same ManagedStatic instance in the StaticList, and asserts when double destroying during llvm_shutdown. I reported this bug [here](https://bugs.llvm.org/show_bug.cgi?id=49027), and learned that this bug had already been fixed in upstream LLVM. Note that llvm_subzero already has a similar change, though for _MSC_VER >= 1920. According to the LLVM comment, the VC++ compiler up until 1925 may still emit a dynamic initializer for a constexpr constructor, but I suppose we never ran into that for Subzero, so I'll leave this as is. Bug: b/175782868 Change-Id: Ice3944f67e496aa94f1a7ed7502b49e763d702b4 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/52508 Kokoro-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Tested-by: 's avatarAntonio Maiorano <amaiorano@google.com> Commit-Queue: Antonio Maiorano <amaiorano@google.com>
parent a8da847d
...@@ -40,8 +40,8 @@ template <typename T, size_t N> struct object_deleter<T[N]> { ...@@ -40,8 +40,8 @@ template <typename T, size_t N> struct object_deleter<T[N]> {
// constexpr, a dynamic initializer may be emitted depending on optimization // constexpr, a dynamic initializer may be emitted depending on optimization
// settings. For the affected versions of MSVC, use the old linker // settings. For the affected versions of MSVC, use the old linker
// initialization pattern of not providing a constructor and leaving the fields // initialization pattern of not providing a constructor and leaving the fields
// uninitialized. // uninitialized. See http://llvm.org/PR41367 for details.
#if !defined(_MSC_VER) || defined(__clang__) #if !defined(_MSC_VER) || (_MSC_VER >= 1925) || defined(__clang__)
#define LLVM_USE_CONSTEXPR_CTOR #define LLVM_USE_CONSTEXPR_CTOR
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment