diff --git a/llvm/include/llvm/Support/CommandLine.h b/llvm/include/llvm/Support/CommandLine.h index b035209406b68..8acdd5b12efae 100644 --- a/llvm/include/llvm/Support/CommandLine.h +++ b/llvm/include/llvm/Support/CommandLine.h @@ -865,6 +865,7 @@ template class parser : public generic_parser_base { for (size_t i = 0, e = Values.size(); i != e; ++i) if (Values[i].Name == ArgVal) { + O.setValueStr(Values[i].Name); V = Values[i].V.getValue(); return false; } diff --git a/llvm/unittests/Support/CommandLineTest.cpp b/llvm/unittests/Support/CommandLineTest.cpp index 23f6081cd32a4..2f8095efbdb4d 100644 --- a/llvm/unittests/Support/CommandLineTest.cpp +++ b/llvm/unittests/Support/CommandLineTest.cpp @@ -2329,4 +2329,33 @@ TEST(CommandLineTest, HelpWithEmptyCategory) { cl::ResetCommandLineParser(); } +class ValueStrTestParser : public cl::parser { +public: + ValueStrTestParser(cl::Option &O) : cl::parser(O) {} + + void initialize() { + cl::parser::initialize(); + + this->addLiteralOption("default", "", ""); + this->addLiteralOption("first_option", "1", ""); + this->addLiteralOption("other_option", "2", ""); + this->addLiteralOption("expected_option", "3", ""); + this->addLiteralOption("another_option", "4", ""); + } +}; + +TEST(CommandLineTest, ValueStr) { + cl::ResetCommandLineParser(); + + cl::opt Option("option", + cl::init("default")); + const char *args[] = {"prog", "-option=expected_option"}; + + EXPECT_TRUE(cl::ParseCommandLineOptions(std::size(args), args, StringRef(), + &llvm::nulls())); + + EXPECT_EQ(Option.ArgStr, "option"); + EXPECT_EQ(Option.ValueStr, "expected_option"); +} + } // anonymous namespace