diff options
author | Mehdi Amini <joker.eph@gmail.com> | 2021-07-15 23:52:44 +0000 |
---|---|---|
committer | Mehdi Amini <joker.eph@gmail.com> | 2021-07-16 06:54:26 +0000 |
commit | af9321739b20becf170e6bb5060b8d780e1dc8dd (patch) | |
tree | b6102c00e02d67904fab6a4638b0f0e3d1afca9b /llvm/lib/Support/GraphWriter.cpp | |
parent | 20113d66c7bfe935cf2b300fc6cc3ef996bb847d (diff) | |
download | llvm-af9321739b20becf170e6bb5060b8d780e1dc8dd.zip llvm-af9321739b20becf170e6bb5060b8d780e1dc8dd.tar.gz llvm-af9321739b20becf170e6bb5060b8d780e1dc8dd.tar.bz2 |
Use ManagedStatic and lazy initialization of cl::opt in libSupport to make it free of global initializer
We can build it with -Werror=global-constructors now. This helps
in situation where libSupport is embedded as a shared library,
potential with dlopen/dlclose scenario, and when command-line
parsing or other facilities may not be involved. Avoiding the
implicit construction of these cl::opt can avoid double-registration
issues and other kind of behavior.
Reviewed By: lattner, jpienaar
Differential Revision: https://reviews.llvm.org/D105959
Diffstat (limited to 'llvm/lib/Support/GraphWriter.cpp')
-rw-r--r-- | llvm/lib/Support/GraphWriter.cpp | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/llvm/lib/Support/GraphWriter.cpp b/llvm/lib/Support/GraphWriter.cpp index f47a52a..240f597 100644 --- a/llvm/lib/Support/GraphWriter.cpp +++ b/llvm/lib/Support/GraphWriter.cpp @@ -11,6 +11,9 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/GraphWriter.h" + +#include "DebugOptions.h" + #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" @@ -29,8 +32,21 @@ using namespace llvm; -static cl::opt<bool> ViewBackground("view-background", cl::Hidden, - cl::desc("Execute graph viewer in the background. Creates tmp file litter.")); +#ifdef __APPLE__ +namespace { +struct CreateViewBackground { + static void *call() { + return new cl::opt<bool>("view-background", cl::Hidden, + cl::desc("Execute graph viewer in the background. " + "Creates tmp file litter.")); + } +}; +} // namespace +static ManagedStatic<cl::opt<bool>, CreateViewBackground> ViewBackground; +void llvm::initGraphWriterOptions() { *ViewBackground; } +#else +void llvm::initGraphWriterOptions() {} +#endif std::string llvm::DOT::EscapeString(const std::string &Label) { std::string Str(Label); |