aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Support/CommandLineTest.cpp
diff options
context:
space:
mode:
authorRVP <riyaz@synopsys.com>2022-02-08 16:06:53 +0100
committerserge-sans-paille <sguelton@redhat.com>2022-02-09 09:46:46 +0100
commit62e4a77746f4f6dd810f49644fd1f6cebda2235f (patch)
tree90e205c3bf5949a207a0d95ce4147073ab8c29a6 /llvm/unittests/Support/CommandLineTest.cpp
parentfda29264f360820859587acdfb0ad9392c944bd6 (diff)
downloadllvm-62e4a77746f4f6dd810f49644fd1f6cebda2235f.zip
llvm-62e4a77746f4f6dd810f49644fd1f6cebda2235f.tar.gz
llvm-62e4a77746f4f6dd810f49644fd1f6cebda2235f.tar.bz2
[Support] Fix for two issues with clearing of the internal storage for cl::bits
This patch fixes two issues with clearing of the internal storage for cl::bits 1. The internal bits storage for cl::bits is uninitialized. This is a problem if a cl::bits option is not defined with static lifetime. 2. ResetAllOptionOccurrences does not reset cl::bits options. The latter is also discussed in: https://lists.llvm.org/pipermail/llvm-dev/2021-February/148299.html Differential Revision: https://reviews.llvm.org/D119066
Diffstat (limited to 'llvm/unittests/Support/CommandLineTest.cpp')
-rw-r--r--llvm/unittests/Support/CommandLineTest.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/llvm/unittests/Support/CommandLineTest.cpp b/llvm/unittests/Support/CommandLineTest.cpp
index 8032d0e7..2e007bf 100644
--- a/llvm/unittests/Support/CommandLineTest.cpp
+++ b/llvm/unittests/Support/CommandLineTest.cpp
@@ -1931,20 +1931,27 @@ TEST(CommandLineTest, ConsumeAfterTwoPositionals) {
TEST(CommandLineTest, ResetAllOptionOccurrences) {
cl::ResetCommandLineParser();
- // -option [sink] input [args]
+ // -option -enableA -enableC [sink] input [args]
StackOption<bool> Option("option");
+ enum Vals { ValA, ValB, ValC };
+ StackOption<Vals, cl::bits<Vals>> Bits(
+ cl::values(clEnumValN(ValA, "enableA", "Enable A"),
+ clEnumValN(ValB, "enableB", "Enable B"),
+ clEnumValN(ValC, "enableC", "Enable C")));
StackOption<std::string, cl::list<std::string>> Sink(cl::Sink);
StackOption<std::string> Input(cl::Positional);
StackOption<std::string, cl::list<std::string>> ExtraArgs(cl::ConsumeAfter);
- const char *Args[] = {"prog", "-option", "-unknown", "input", "-arg"};
+ const char *Args[] = {"prog", "-option", "-enableA", "-enableC",
+ "-unknown", "input", "-arg"};
std::string Errs;
raw_string_ostream OS(Errs);
- EXPECT_TRUE(cl::ParseCommandLineOptions(5, Args, StringRef(), &OS));
+ EXPECT_TRUE(cl::ParseCommandLineOptions(7, Args, StringRef(), &OS));
EXPECT_TRUE(OS.str().empty());
EXPECT_TRUE(Option);
+ EXPECT_EQ((1u << ValA) | (1u << ValC), Bits.getBits());
EXPECT_EQ(1u, Sink.size());
EXPECT_EQ("-unknown", Sink[0]);
EXPECT_EQ("input", Input);
@@ -1953,6 +1960,7 @@ TEST(CommandLineTest, ResetAllOptionOccurrences) {
cl::ResetAllOptionOccurrences();
EXPECT_FALSE(Option);
+ EXPECT_EQ(0u, Bits.getBits());
EXPECT_EQ(0u, Sink.size());
EXPECT_EQ(0, Input.getNumOccurrences());
EXPECT_EQ(0u, ExtraArgs.size());