Commit dc0f1319 by Antonio Maiorano

Subzero: fix partially initialized ManagedStatic assert

This is the same fix that I applied to LLVM7 here: https://swiftshader-review.googlesource.com/c/SwiftShader/+/37608 but this time to subzero-llvm. Fixes ANGLE dEQP tests run against SwiftShader/Subzero. Bug: chromium:151653536 Change-Id: Ia4725b74d068a3afd99d407c53b11f757bc5e11f Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/42469 Presubmit-Ready: Antonio Maiorano <amaiorano@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarAntonio Maiorano <amaiorano@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 2aa80df1
...@@ -243,6 +243,15 @@ ...@@ -243,6 +243,15 @@
#define LLVM_FALLTHROUGH #define LLVM_FALLTHROUGH
#endif #endif
/// LLVM_REQUIRE_CONSTANT_INITIALIZATION - Apply this to globals to ensure that
/// they are constant initialized.
#if __has_cpp_attribute(clang::require_constant_initialization)
#define LLVM_REQUIRE_CONSTANT_INITIALIZATION \
[[clang::require_constant_initialization]]
#else
#define LLVM_REQUIRE_CONSTANT_INITIALIZATION
#endif
/// LLVM_EXTENSION - Support compilers where we have a keyword to suppress /// LLVM_EXTENSION - Support compilers where we have a keyword to suppress
/// pedantic diagnostics. /// pedantic diagnostics.
#ifdef __GNUC__ #ifdef __GNUC__
......
...@@ -36,18 +36,37 @@ struct LLVM_LIBRARY_VISIBILITY object_deleter<T[N]> { ...@@ -36,18 +36,37 @@ struct LLVM_LIBRARY_VISIBILITY object_deleter<T[N]> {
static void call(void *Ptr) { delete[](T *)Ptr; } static void call(void *Ptr) { delete[](T *)Ptr; }
}; };
// If the current compiler is MSVC 2017 or earlier, then we have to work around
// a bug where MSVC emits code to perform dynamic initialization even if the
// class has a constexpr constructor. Instead, fall back to the C++98 strategy
// where there are no constructors or member initializers. We can remove this
// when MSVC 2019 (19.20+) is our minimum supported version.
#if !defined(__clang__) && defined(_MSC_VER) && _MSC_VER < 1920
#define LLVM_AVOID_CONSTEXPR_CTOR
#endif
/// ManagedStaticBase - Common base class for ManagedStatic instances. /// ManagedStaticBase - Common base class for ManagedStatic instances.
class ManagedStaticBase { class ManagedStaticBase {
protected: protected:
#ifndef LLVM_AVOID_CONSTEXPR_CTOR
mutable std::atomic<void *> Ptr{};
mutable void (*DeleterFn)(void *) = nullptr;
mutable const ManagedStaticBase *Next = nullptr;
#else
// This should only be used as a static variable, which guarantees that this // This should only be used as a static variable, which guarantees that this
// will be zero initialized. // will be zero initialized.
mutable std::atomic<void *> Ptr; mutable std::atomic<void *> Ptr;
mutable void (*DeleterFn)(void*); mutable void (*DeleterFn)(void *);
mutable const ManagedStaticBase *Next; mutable const ManagedStaticBase *Next;
#endif
void RegisterManagedStatic(void *(*creator)(), void (*deleter)(void*)) const; void RegisterManagedStatic(void *(*creator)(), void (*deleter)(void*)) const;
public: public:
#ifndef LLVM_AVOID_CONSTEXPR_CTOR
constexpr ManagedStaticBase() = default;
#endif
/// isConstructed - Return true if this object has not been created yet. /// isConstructed - Return true if this object has not been created yet.
bool isConstructed() const { return Ptr != nullptr; } bool isConstructed() const { return Ptr != nullptr; }
......
...@@ -383,11 +383,16 @@ void OptionCategory::registerCategory() { ...@@ -383,11 +383,16 @@ void OptionCategory::registerCategory() {
GlobalParser->registerCategory(this); GlobalParser->registerCategory(this);
} }
// A special subcommand representing no subcommand // A special subcommand representing no subcommand. It is particularly important
ManagedStatic<SubCommand> llvm::cl::TopLevelSubCommand; // 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. // 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() { void SubCommand::registerSubCommand() {
GlobalParser->registerSubCommand(this); GlobalParser->registerSubCommand(this);
......
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