From 42f588f39c5ce6f521e3709b8871d1fdd076292f Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Thu, 15 Jul 2021 23:52:44 +0000 Subject: 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 --- llvm/unittests/Support/CommandLineTest.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'llvm/unittests/Support/CommandLineTest.cpp') diff --git a/llvm/unittests/Support/CommandLineTest.cpp b/llvm/unittests/Support/CommandLineTest.cpp index 7d88046..a0352bc 100644 --- a/llvm/unittests/Support/CommandLineTest.cpp +++ b/llvm/unittests/Support/CommandLineTest.cpp @@ -110,7 +110,7 @@ TEST(CommandLineTest, ModifyExisitingOption) { 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, UseOptionCategory) { 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 @@ TEST(CommandLineTest, UseMultipleCategories) { << "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 @@ TEST(CommandLineTest, UseMultipleCategories) { 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, -- cgit v1.1