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

2021-07-16 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

In D105959#2883954 , @mehdi_amini 
wrote:

> That's interesting!
>
> I'm not sure how to get there though: a complete solution should be able to 
> "degrade" to global constructor when the platform-specific logic isn't 
> available (unless we're confident that no such environment can exist?).

Right, it needs to downgrade (and I think there should be a CMake flag to turn 
it off in case there are reasons some LLVM user doesn't want it).

I think this would work:

  #ifdef USE_DARWIN_CLOPT
  // Add F to the list of initializers for LLVMSupport to iterate through.
  #define LLVM_ADD_CLOPT_CONSTRUCTOR(F, V) \
__attribute__((section("__DATA,__llvmopts"),visibility("hidden"))) \
void (*V)() = F;
  #elif defined(...) // Handle magic for other platforms.
  #else
  // Create a local symbol with a static initializer that calls F.
  #define LLVM_ADD_CLOPT_CONSTRUCTOR(F, V) \
namespace { struct V##Type { V##Type() { F(); } } V; }
  #endif
  
  void initOptions();
  // Add an options constructor the array of cl::opt initializers.
  LLVM_ADD_CLOPT_CONSTRUCTOR(initOptions, OptionsConstructorVariable);

but maybe there's a cleaner downgrade that doesn't add an extra type.

In D105959#2883956 , @mehdi_amini 
wrote:

> Something else I'm not sure about is how it works across DSOs: when each LLVM 
> library is linked into its own shared library, is the dynamic linker creating 
> this array when loading the libraries? (I'm starting to doubt about how this 
> would even work on windows)

Yeah, this technique only works within a single final linked image. It'd need 
to be off when the library isn't statically linked to LLVMSupport.

I imagine we'd want CMake to just "get this right" for us, but we can also 
enforce this at link time to catch configuration errors -- add a 
(dead-strippable) symbol to LLVMSupport that's `visibility("hidden")`, and 
manufacture a (dead-strippable) reference to it in any TU that uses the macro. 
If the TU ends up in a different linked image than LLVMSupport you'll get a 
link error.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105959

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2021-07-16 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added a comment.

It's just a standard linker set; the static linker combines all the input 
sections containing the array elements into a single output section. It's 
similar to init_array etc, just without the special meaning (i.e. you have to 
write the code to iterate over the array and do what you want).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105959

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2021-07-16 Thread Mehdi AMINI via Phabricator via cfe-commits
mehdi_amini added a comment.

Something else I'm not sure about is how it works across DSOs: when each LLVM 
library is linked into its own shared library, is the dynamic linker creating 
this array when loading the libraries?
(I'm starting to doubt about how this would even work on windows)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105959

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2021-07-16 Thread Mehdi AMINI via Phabricator via cfe-commits
mehdi_amini added a comment.

That's interesting!

I'm not sure how to get there though: a complete solution should be able to 
"degrade" to global constructor when the platform-specific logic isn't 
available (unless we're confident that no such environment can exist?).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105959

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2021-07-16 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

In D105959#2882136 , @mehdi_amini 
wrote:

> In D105959#2882099 , @bondhugula 
> wrote:
>
>> This is a really welcome change! Multiple registration issues were really an 
>> inconvenience - I had no clue this was the pattern to use to fix it. Thanks!
>
> To be fair: we can do it transparently only for libSupport, as it contains 
> the entry point for command line parsing it can explicitly trigger the 
> registration of the options for itself. Other libraries in LLVM don't have 
> this luxury...

We could probably combine this with the technique used to avoid static 
constructors in compiler-rt/lib/profile to pick up other libraries in the same 
final linked image. The idea would be to ask the linker to build an array of 
initializer functions that LLVMSupport could iterate through to initialize 
options it doesn't know about.

For example, on Darwin, this code adds an initializer to a global array in 
section `__DATA,__llvmopts`:

  using OptionConstructorT = void (*)(); // Declared in LLVMSupport headers to 
get safety.
  
  void initOptions();
  
  // Add an options constructor the array of cl::opt initializers.
  __attribute__((section("__DATA,__llvmopts"),visibility("hidden")))
  OptionConstructorT OptionsConstructor = initOptions;

Also on Darwin, this could go in LLVMSupport to access it:

  using OptionConstructorT = void (*)(); // Declared in LLVMSupport headers to 
get safety.
  
  // Declare symbols to access the global array.
  extern OptionConstructorT *ExternalOptionsInitBegin
__asm("section$start$__DATA$__llvmopts");
  extern OptionConstructorT *ExternalOptionsInitEnd
__asm("section$end$__DATA$__llvmopts");
  
  void initCommonOptions();
  void initOptions() {
initCommonOptions();
// Iterate through external initializers for options.
for (auto I = ExternalOptionsInitBegin, E = ExternalOptionsInitEnd; I != E; 
++I)
  (*I)();
  }

The relevant code for other platforms is in 
`compiler-rt/lib/profile/InstrProfilingPlatform*.c`.

If we did this, we'd maybe want to control it with a CMake configuration? When 
off (always for platforms where we don't have/know the magic incantations), the 
various `initOptions()` would be added to static initializers as before. When 
on, we could add `-Werror=global-constructors` to other libraries (once they're 
clean).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105959

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2021-07-16 Thread Mehdi AMINI via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG42f588f39c5c: Use ManagedStatic and lazy initialization of 
cl::opt in libSupport to make it… (authored by mehdi_amini).

Changed prior to commit:
  https://reviews.llvm.org/D105959?vs=359196&id=359201#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105959

Files:
  clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
  clang-tools-extra/clangd/indexer/IndexerMain.cpp
  clang/tools/clang-refactor/ClangRefactor.cpp
  llvm/docs/CommandLine.rst
  llvm/include/llvm/Support/ARMAttributeParser.h
  llvm/include/llvm/Support/ARMBuildAttributes.h
  llvm/include/llvm/Support/CommandLine.h
  llvm/include/llvm/Support/RISCVAttributeParser.h
  llvm/include/llvm/Support/RISCVAttributes.h
  llvm/include/llvm/Support/ScopedPrinter.h
  llvm/include/llvm/Support/WithColor.h
  llvm/lib/Support/ARMBuildAttrs.cpp
  llvm/lib/Support/CommandLine.cpp
  llvm/lib/Support/Debug.cpp
  llvm/lib/Support/DebugCounter.cpp
  llvm/lib/Support/DebugOptions.h
  llvm/lib/Support/ELFAttributeParser.cpp
  llvm/lib/Support/GraphWriter.cpp
  llvm/lib/Support/RISCVAttributes.cpp
  llvm/lib/Support/RandomNumberGenerator.cpp
  llvm/lib/Support/Signals.cpp
  llvm/lib/Support/Statistic.cpp
  llvm/lib/Support/TimeProfiler.cpp
  llvm/lib/Support/Timer.cpp
  llvm/lib/Support/TypeSize.cpp
  llvm/lib/Support/Windows/Signals.inc
  llvm/lib/Support/WithColor.cpp
  llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
  llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
  llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
  llvm/unittests/Support/ARMAttributeParser.cpp
  llvm/unittests/Support/CommandLineTest.cpp
  llvm/unittests/Support/RISCVAttributeParserTest.cpp

Index: llvm/unittests/Support/RISCVAttributeParserTest.cpp
===
--- llvm/unittests/Support/RISCVAttributeParserTest.cpp
+++ llvm/unittests/Support/RISCVAttributeParserTest.cpp
@@ -49,7 +49,7 @@
 }
 
 static bool testTagString(unsigned Tag, const char *name) {
-  return ELFAttrs::attrTypeAsString(Tag, RISCVAttrs::RISCVAttributeTags)
+  return ELFAttrs::attrTypeAsString(Tag, RISCVAttrs::getRISCVAttributeTags())
  .str() == name;
 }
 
Index: llvm/unittests/Support/CommandLineTest.cpp
===
--- llvm/unittests/Support/CommandLineTest.cpp
+++ llvm/unittests/Support/CommandLineTest.cpp
@@ -110,7 +110,7 @@
   ASSERT_NE(Retrieved->Categories.end(),
 find_if(Retrieved->Categories,
 [&](const llvm::cl::OptionCategory *Cat) {
-  return Cat == &cl::GeneralCategory;
+  return Cat == &cl::getGeneralCategory();
 }))
   << "Incorrect default option category.";
 
@@ -152,10 +152,10 @@
 
 TEST(CommandLineTest, UseMultipleCategories) {
   StackOption TestOption2("test-option2", cl::cat(TestCategory),
-   cl::cat(cl::GeneralCategory),
-   cl::cat(cl::GeneralCategory));
+   cl::cat(cl::getGeneralCategory()),
+   cl::cat(cl::getGeneralCategory()));
 
-  // Make sure cl::GeneralCategory wasn't added twice.
+  // Make sure cl::getGeneralCategory() wasn't added twice.
   ASSERT_EQ(TestOption2.Categories.size(), 2U);
 
   ASSERT_NE(TestOption2.Categories.end(),
@@ -166,9 +166,9 @@
   << "Failed to assign Option Category.";
   ASSERT_NE(TestOption2.Categories.end(),
 find_if(TestOption2.Categories,
- [&](const llvm::cl::OptionCategory *Cat) {
-   return Cat == &cl::GeneralCategory;
- }))
+[&](const llvm::cl::OptionCategory *Cat) {
+  return Cat == &cl::getGeneralCategory();
+}))
   << "Failed to assign General Category.";
 
   cl::OptionCategory AnotherCategory("Additional test Options", "Description");
@@ -176,9 +176,9 @@
   cl::cat(AnotherCategory));
   ASSERT_EQ(TestOption.Categories.end(),
 find_if(TestOption.Categories,
- [&](const llvm::cl::OptionCategory *Cat) {
-   return Cat == &cl::GeneralCategory;
- }))
+[&](const llvm::cl::OptionCategory *Cat) {
+  return Cat == &cl::getGeneralCategory();
+}))
   << "Failed to remove General Category.";
   ASSERT_NE(TestOption.Categories.end(),
 find_if(TestOption.Categories,
Index: llvm/unittests/Support/ARMAttributeParser.cpp
==

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

2021-07-16 Thread Mehdi AMINI via Phabricator via cfe-commits
mehdi_amini added a comment.

In D105959#2882099 , @bondhugula 
wrote:

> This is a really welcome change! Multiple registration issues were really an 
> inconvenience - I had no clue this was the pattern to use to fix it. Thanks!

To be fair: we can do it transparently only for libSupport, as it contains the 
entry point for command line parsing it can explicitly trigger the registration 
of the options for itself. Other libraries in LLVM don't have this luxury...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105959

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2021-07-16 Thread Mehdi AMINI via Phabricator via cfe-commits
mehdi_amini updated this revision to Diff 359196.
mehdi_amini added a comment.

Fix windows build


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105959

Files:
  clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
  clang-tools-extra/clangd/indexer/IndexerMain.cpp
  clang/tools/clang-refactor/ClangRefactor.cpp
  llvm/docs/CommandLine.rst
  llvm/include/llvm/Support/ARMAttributeParser.h
  llvm/include/llvm/Support/ARMBuildAttributes.h
  llvm/include/llvm/Support/CommandLine.h
  llvm/include/llvm/Support/RISCVAttributeParser.h
  llvm/include/llvm/Support/RISCVAttributes.h
  llvm/include/llvm/Support/ScopedPrinter.h
  llvm/include/llvm/Support/WithColor.h
  llvm/lib/Support/ARMBuildAttrs.cpp
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/CommandLine.cpp
  llvm/lib/Support/Debug.cpp
  llvm/lib/Support/DebugCounter.cpp
  llvm/lib/Support/DebugOptions.h
  llvm/lib/Support/ELFAttributeParser.cpp
  llvm/lib/Support/GraphWriter.cpp
  llvm/lib/Support/RISCVAttributes.cpp
  llvm/lib/Support/RandomNumberGenerator.cpp
  llvm/lib/Support/Signals.cpp
  llvm/lib/Support/Statistic.cpp
  llvm/lib/Support/TimeProfiler.cpp
  llvm/lib/Support/Timer.cpp
  llvm/lib/Support/TypeSize.cpp
  llvm/lib/Support/Windows/Signals.inc
  llvm/lib/Support/WithColor.cpp
  llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
  llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
  llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
  llvm/unittests/Support/ARMAttributeParser.cpp
  llvm/unittests/Support/CommandLineTest.cpp
  llvm/unittests/Support/RISCVAttributeParserTest.cpp

Index: llvm/unittests/Support/RISCVAttributeParserTest.cpp
===
--- llvm/unittests/Support/RISCVAttributeParserTest.cpp
+++ llvm/unittests/Support/RISCVAttributeParserTest.cpp
@@ -49,7 +49,7 @@
 }
 
 static bool testTagString(unsigned Tag, const char *name) {
-  return ELFAttrs::attrTypeAsString(Tag, RISCVAttrs::RISCVAttributeTags)
+  return ELFAttrs::attrTypeAsString(Tag, RISCVAttrs::getRISCVAttributeTags())
  .str() == name;
 }
 
Index: llvm/unittests/Support/CommandLineTest.cpp
===
--- llvm/unittests/Support/CommandLineTest.cpp
+++ llvm/unittests/Support/CommandLineTest.cpp
@@ -110,7 +110,7 @@
   ASSERT_NE(Retrieved->Categories.end(),
 find_if(Retrieved->Categories,
 [&](const llvm::cl::OptionCategory *Cat) {
-  return Cat == &cl::GeneralCategory;
+  return Cat == &cl::getGeneralCategory();
 }))
   << "Incorrect default option category.";
 
@@ -152,10 +152,10 @@
 
 TEST(CommandLineTest, UseMultipleCategories) {
   StackOption TestOption2("test-option2", cl::cat(TestCategory),
-   cl::cat(cl::GeneralCategory),
-   cl::cat(cl::GeneralCategory));
+   cl::cat(cl::getGeneralCategory()),
+   cl::cat(cl::getGeneralCategory()));
 
-  // Make sure cl::GeneralCategory wasn't added twice.
+  // Make sure cl::getGeneralCategory() wasn't added twice.
   ASSERT_EQ(TestOption2.Categories.size(), 2U);
 
   ASSERT_NE(TestOption2.Categories.end(),
@@ -166,9 +166,9 @@
   << "Failed to assign Option Category.";
   ASSERT_NE(TestOption2.Categories.end(),
 find_if(TestOption2.Categories,
- [&](const llvm::cl::OptionCategory *Cat) {
-   return Cat == &cl::GeneralCategory;
- }))
+[&](const llvm::cl::OptionCategory *Cat) {
+  return Cat == &cl::getGeneralCategory();
+}))
   << "Failed to assign General Category.";
 
   cl::OptionCategory AnotherCategory("Additional test Options", "Description");
@@ -176,9 +176,9 @@
   cl::cat(AnotherCategory));
   ASSERT_EQ(TestOption.Categories.end(),
 find_if(TestOption.Categories,
- [&](const llvm::cl::OptionCategory *Cat) {
-   return Cat == &cl::GeneralCategory;
- }))
+[&](const llvm::cl::OptionCategory *Cat) {
+  return Cat == &cl::getGeneralCategory();
+}))
   << "Failed to remove General Category.";
   ASSERT_NE(TestOption.Categories.end(),
 find_if(TestOption.Categories,
Index: llvm/unittests/Support/ARMAttributeParser.cpp
===
--- llvm/unittests/Support/ARMAttributeParser.cpp
+++ llvm/unittests/Support/ARMAttributeParser.cpp
@@ -48,7 +48,7 @@
 }
 
 bool testTagString(unsigned Tag, const char *name) {
-  return ELFAttrs::attrTypeAsS

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

2021-07-16 Thread Uday Bondhugula via Phabricator via cfe-commits
bondhugula added a comment.

This is a really welcome change! Multiple registration issues were really an 
inconvenience - I had no clue this was the pattern to use to fix it. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105959

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2021-07-16 Thread Mehdi AMINI via Phabricator via cfe-commits
mehdi_amini updated this revision to Diff 359191.
mehdi_amini marked 7 inline comments as done.
mehdi_amini added a comment.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman.
Herald added projects: clang, clang-tools-extra.

Address comment and fix build errors


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105959

Files:
  clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
  clang-tools-extra/clangd/indexer/IndexerMain.cpp
  clang/tools/clang-refactor/ClangRefactor.cpp
  llvm/docs/CommandLine.rst
  llvm/include/llvm/Support/ARMAttributeParser.h
  llvm/include/llvm/Support/ARMBuildAttributes.h
  llvm/include/llvm/Support/CommandLine.h
  llvm/include/llvm/Support/RISCVAttributeParser.h
  llvm/include/llvm/Support/RISCVAttributes.h
  llvm/include/llvm/Support/ScopedPrinter.h
  llvm/include/llvm/Support/WithColor.h
  llvm/lib/Support/ARMBuildAttrs.cpp
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/CommandLine.cpp
  llvm/lib/Support/Debug.cpp
  llvm/lib/Support/DebugCounter.cpp
  llvm/lib/Support/DebugOptions.h
  llvm/lib/Support/ELFAttributeParser.cpp
  llvm/lib/Support/GraphWriter.cpp
  llvm/lib/Support/RISCVAttributes.cpp
  llvm/lib/Support/RandomNumberGenerator.cpp
  llvm/lib/Support/Signals.cpp
  llvm/lib/Support/Statistic.cpp
  llvm/lib/Support/TimeProfiler.cpp
  llvm/lib/Support/Timer.cpp
  llvm/lib/Support/TypeSize.cpp
  llvm/lib/Support/WithColor.cpp
  llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
  llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
  llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
  llvm/unittests/Support/ARMAttributeParser.cpp
  llvm/unittests/Support/CommandLineTest.cpp
  llvm/unittests/Support/RISCVAttributeParserTest.cpp

Index: llvm/unittests/Support/RISCVAttributeParserTest.cpp
===
--- llvm/unittests/Support/RISCVAttributeParserTest.cpp
+++ llvm/unittests/Support/RISCVAttributeParserTest.cpp
@@ -49,7 +49,7 @@
 }
 
 static bool testTagString(unsigned Tag, const char *name) {
-  return ELFAttrs::attrTypeAsString(Tag, RISCVAttrs::RISCVAttributeTags)
+  return ELFAttrs::attrTypeAsString(Tag, RISCVAttrs::getRISCVAttributeTags())
  .str() == name;
 }
 
Index: llvm/unittests/Support/CommandLineTest.cpp
===
--- llvm/unittests/Support/CommandLineTest.cpp
+++ llvm/unittests/Support/CommandLineTest.cpp
@@ -110,7 +110,7 @@
   ASSERT_NE(Retrieved->Categories.end(),
 find_if(Retrieved->Categories,
 [&](const llvm::cl::OptionCategory *Cat) {
-  return Cat == &cl::GeneralCategory;
+  return Cat == &cl::getGeneralCategory();
 }))
   << "Incorrect default option category.";
 
@@ -152,10 +152,10 @@
 
 TEST(CommandLineTest, UseMultipleCategories) {
   StackOption TestOption2("test-option2", cl::cat(TestCategory),
-   cl::cat(cl::GeneralCategory),
-   cl::cat(cl::GeneralCategory));
+   cl::cat(cl::getGeneralCategory()),
+   cl::cat(cl::getGeneralCategory()));
 
-  // Make sure cl::GeneralCategory wasn't added twice.
+  // Make sure cl::getGeneralCategory() wasn't added twice.
   ASSERT_EQ(TestOption2.Categories.size(), 2U);
 
   ASSERT_NE(TestOption2.Categories.end(),
@@ -166,9 +166,9 @@
   << "Failed to assign Option Category.";
   ASSERT_NE(TestOption2.Categories.end(),
 find_if(TestOption2.Categories,
- [&](const llvm::cl::OptionCategory *Cat) {
-   return Cat == &cl::GeneralCategory;
- }))
+[&](const llvm::cl::OptionCategory *Cat) {
+  return Cat == &cl::getGeneralCategory();
+}))
   << "Failed to assign General Category.";
 
   cl::OptionCategory AnotherCategory("Additional test Options", "Description");
@@ -176,9 +176,9 @@
   cl::cat(AnotherCategory));
   ASSERT_EQ(TestOption.Categories.end(),
 find_if(TestOption.Categories,
- [&](const llvm::cl::OptionCategory *Cat) {
-   return Cat == &cl::GeneralCategory;
- }))
+[&](const llvm::cl::OptionCategory *Cat) {
+  return Cat == &cl::getGeneralCategory();
+}))
   << "Failed to remove General Category.";
   ASSERT_NE(TestOption.Categories.end(),
 find_if(TestOption.Categories,
Index: llvm/unittests/Support/ARMAttributeParser.cpp
===
--- llvm/unittests/Support/ARMAttributeParser.cpp
+++ llvm/unit

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

2021-07-15 Thread Mehdi AMINI via Phabricator via cfe-commits
mehdi_amini added inline comments.



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)
+

MaskRay wrote:
> Perhaps move this to a separate change.
Sure, I can commit this separately.



Comment at: llvm/lib/Support/Debug.cpp:96
 //until program termination.
-static cl::opt
-DebugBufferSize("debug-buffer-size",
-cl::desc("Buffer the last N characters of debug output "
- "until program termination. "
- "[default 0 -- immediate print-out]"),
-cl::Hidden,
-cl::init(0));
+struct CreateDebugBufferSize {
+  static void *call() {

jpienaar wrote:
> Why not in anonymous namespace too? (consistenly everywhere)
I think it is already?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105959

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits