diff options
author | Reid Kleckner <rnk@google.com> | 2019-04-04 18:30:07 +0000 |
---|---|---|
committer | Reid Kleckner <rnk@google.com> | 2019-04-04 18:30:07 +0000 |
commit | 41fe3a54c2613d81a68eb02ae76b394d0b8849ab (patch) | |
tree | c3f88d5e27f194a2251e0243dce6e9bf285e5cd8 /llvm/lib/Support/CommandLine.cpp | |
parent | 1ee8876d3d703389a27f5e357f67ce1062381e05 (diff) | |
download | llvm-41fe3a54c2613d81a68eb02ae76b394d0b8849ab.zip llvm-41fe3a54c2613d81a68eb02ae76b394d0b8849ab.tar.gz llvm-41fe3a54c2613d81a68eb02ae76b394d0b8849ab.tar.bz2 |
Ensure that ManagedStatic is constant initialized in MSVC 2017 & 2019
Fixes PR41367.
This effectively relands r357655 with a workaround for MSVC 2017.
I tried various approaches with unions, but I ended up going with this
ifdef approach because it lets us write the proper C++11 code that we
want to write, with a separate workaround that we can delete when we
drop MSVC 2017 support.
This also adds LLVM_REQUIRE_CONSTANT_INITIALIZATION, which wraps
[[clang::require_constant_initialization]]. This actually detected a
minor issue when using clang-cl where clang wasn't able to use the
constexpr constructor in MSVC's STL, so I switched back to using the
default ctor of std::atomic<void*>.
llvm-svn: 357714
Diffstat (limited to 'llvm/lib/Support/CommandLine.cpp')
-rw-r--r-- | llvm/lib/Support/CommandLine.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp index c1193f9..d2cfef9f 100644 --- a/llvm/lib/Support/CommandLine.cpp +++ b/llvm/lib/Support/CommandLine.cpp @@ -373,11 +373,16 @@ void OptionCategory::registerCategory() { GlobalParser->registerCategory(this); } -// A special subcommand representing no subcommand -ManagedStatic<SubCommand> llvm::cl::TopLevelSubCommand; +// A special subcommand representing no subcommand. It is particularly important +// 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<SubCommand> + llvm::cl::TopLevelSubCommand; // A special subcommand that can be used to put an option into all subcommands. -ManagedStatic<SubCommand> llvm::cl::AllSubCommands; +LLVM_REQUIRE_CONSTANT_INITIALIZATION ManagedStatic<SubCommand> + llvm::cl::AllSubCommands; void SubCommand::registerSubCommand() { GlobalParser->registerSubCommand(this); |