From c06a470fc84352642e670a0159bb4846f5aa2a3c Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Wed, 24 Apr 2019 20:13:23 +0000 Subject: Try once more to ensure constant initializaton of ManagedStatics First, use the old style of linker initialization for MSVC 2019 in addition to 2017. MSVC 2019 emits a dynamic initializer for ManagedStatic when compiled in debug mode, and according to zturner, also sometimes in release mode. I wasn't able to reproduce that, but it seems best to stick with the old code that works. When clang is using the MSVC STL, we have to give ManagedStatic a constexpr constructor that fully zero initializes all fields, otherwise it emits a dynamic initializer. The MSVC STL implementation of std::atomic has a non-trivial (but constexpr) default constructor that zero initializes the atomic value. Because one of the fields has a non-trivial constructor, ManagedStatic ends up with a non-trivial ctor. The ctor is not constexpr, so clang ends up emitting a dynamic initializer, even though it simply does zero initialization. To make it constexpr, we must initialize all fields of the ManagedStatic. However, while the constructor that takes a pointer is marked constexpr, clang says it does not evaluate to a constant because it contains a cast from a pointer to an integer. I filed this as: https://developercommunity.visualstudio.com/content/problem/545566/stdatomic-value-constructor-is-not-actually-conste.html Once we do that, we can add back the LLVM_REQUIRE_CONSTANT_INITIALIZATION marker, and so far as I'm aware it compiles successfully on all supported targets. llvm-svn: 359135 --- llvm/lib/Support/CommandLine.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'llvm/lib/Support/CommandLine.cpp') diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp index 2f3dc4d..7da38623 100644 --- a/llvm/lib/Support/CommandLine.cpp +++ b/llvm/lib/Support/CommandLine.cpp @@ -412,6 +412,7 @@ void OptionCategory::registerCategory() { // that this ManagedStatic uses constant initailization and not dynamic // initialization because it is referenced from cl::opt constructors, which run // dynamically in an arbitrary order. +LLVM_REQUIRE_CONSTANT_INITIALIZATION ManagedStatic llvm::cl::TopLevelSubCommand; // A special subcommand that can be used to put an option into all subcommands. -- cgit v1.1