Ensure that ManagedStatic is constant initialized in MSVC 2017 & 2019
authorReid Kleckner <rnk@google.com>
Thu, 4 Apr 2019 18:30:07 +0000 (18:30 +0000)
committerReid Kleckner <rnk@google.com>
Thu, 4 Apr 2019 18:30:07 +0000 (18:30 +0000)
commit41fe3a54c2613d81a68eb02ae76b394d0b8849ab
treec3f88d5e27f194a2251e0243dce6e9bf285e5cd8
parent1ee8876d3d703389a27f5e357f67ce1062381e05
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
llvm/include/llvm/Support/Compiler.h
llvm/include/llvm/Support/ManagedStatic.h
llvm/lib/Support/CommandLine.cpp