[PATCH] D105959: Use ManagedStatic and lazy initialization of cl::opt in libSupport to make it free of global initializer

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 15 14:09:36 PDT 2021


MaskRay added a comment.

If you have installed valgrind:

  /home/maskray/llvm/llvm/lib/Support/Valgrind.cpp:30:19: error: declaration requires a global constructor [-Werror,-Wglobal-constructors]
  static const bool NotUnderValgrind = InitNotUnderValgrind();



================
Comment at: llvm/lib/Support/ARMBuildAttrs.cpp:13
 
-static const TagNameItem tagData[] = {
+static constexpr TagNameItem tagData[] = {
     {ARMBuildAttrs::File, "Tag_File"},
----------------
This change is unrelated to removing dynamic initializations.

const objects at namespace level has internal linkage so you can omit `static`.


================
Comment at: llvm/lib/Support/CMakeLists.txt:7
+# ManagedStatic can be used to enable lazy-initialization of globals.
+add_flag_if_supported("-Werror=global-constructors" WERROR_GLOBAL_CONSTRUCTOR)
+
----------------
Perhaps move this to a separate change.


================
Comment at: llvm/lib/Support/CommandLine.cpp:2440
 
-    if (OverrideVersionPrinter != nullptr) {
-      OverrideVersionPrinter(outs());
-      exit(0);
-    }
-    print();
-
-    // Iterate over any registered extra printers and call them to add further
-    // information.
-    if (ExtraVersionPrinters != nullptr) {
-      outs() << '\n';
-      for (const auto &I : *ExtraVersionPrinters)
-        I(outs());
-    }
+struct CommandLineCommonOptions {
+  // Declare the four HelpPrinter instances that are used to print out help, or
----------------
unnamed namespace


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105959/new/

https://reviews.llvm.org/D105959



More information about the llvm-commits mailing list