Skip to content

Commit 2e912a2

Browse files
Revert "[Support]Look up in top-level subcommand as a fallback when looking options for a custom subcommand (#71975)
…ooking options for a custom subcommand. (#71776)" This reverts commit b88308b. The build-bot is unhappy (https://lab.llvm.org/buildbot/#/builders/186/builds/13096), `GroupingAndPrefix` fails after `TopLevelOptInSubcommand` (the newly added test). Revert while I look into this (might be related with test sharding but not sure) ``` [----------] 3 tests from CommandLineTest [ RUN ] CommandLineTest.TokenizeWindowsCommandLine2 [ OK ] CommandLineTest.TokenizeWindowsCommandLine2 (0 ms) [ RUN ] CommandLineTest.TopLevelOptInSubcommand [ OK ] CommandLineTest.TopLevelOptInSubcommand (0 ms) [ RUN ] CommandLineTest.GroupingAndPrefix #0 0x00ba8118 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/tcwg-buildbot/worker/clang-armv7-global-isel/stage1/unittests/Support/./SupportTests+0x594118) #1 0x00ba5914 llvm::sys::RunSignalHandlers() (/home/tcwg-buildbot/worker/clang-armv7-global-isel/stage1/unittests/Support/./SupportTests+0x591914) #2 0x00ba89c4 SignalHandler(int) (/home/tcwg-buildbot/worker/clang-armv7-global-isel/stage1/unittests/Support/./SupportTests+0x5949c4) #3 0xf7828530 __default_sa_restorer /build/glibc-9MGTF6/glibc-2.31/signal/../sysdeps/unix/sysv/linux/arm/sigrestorer.S:67:0 #4 0x00af91f0 (anonymous namespace)::CommandLineParser::ResetAllOptionOccurrences() (/home/tcwg-buildbot/worker/clang-armv7-global-isel/stage1/unittests/Support/./SupportTests+0x4e51f0) #5 0x00af8e1c llvm::cl::ResetCommandLineParser() (/home/tcwg-buildbot/worker/clang-armv7-global-isel/stage1/unittests/Support/./SupportTests+0x4e4e1c) #6 0x0077cda0 (anonymous namespace)::CommandLineTest_GroupingAndPrefix_Test::TestBody() (/home/tcwg-buildbot/worker/clang-armv7-global-isel/stage1/unittests/Support/./SupportTests+0x168da0) #7 0x00bc5adc testing::Test::Run() (/home/tcwg-buildbot/worker/clang-armv7-global-isel/stage1/unittests/Support/./SupportTests+0x5b1adc) #8 0x00bc6cc0 testing::TestInfo::Run() (/home/tcwg-buildbot/worker/clang-armv7-global-isel/stage1/unittests/Support/./SupportTests+0x5b2cc0) #9 0x00bc7880 testing::TestSuite::Run() (/home/tcwg-buildbot/worker/clang-armv7-global-isel/stage1/unittests/Support/./SupportTests+0x5b3880) #10 0x00bd7974 testing::internal::UnitTestImpl::RunAllTests() (/home/tcwg-buildbot/worker/clang-armv7-global-isel/stage1/unittests/Support/./SupportTests+0x5c3974) #11 0x00bd6ebc testing::UnitTest::Run() (/home/tcwg-buildbot/worker/clang-armv7-global-isel/stage1/unittests/Support/./SupportTests+0x5c2ebc) #12 0x00bb1058 main (/home/tcwg-buildbot/worker/clang-armv7-global-isel/stage1/unittests/Support/./SupportTests+0x59d058) #13 0xf78185a4 __libc_start_main /build/glibc-9MGTF6/glibc-2.31/csu/libc-start.c:342:3 ```
1 parent f2f5f1b commit 2e912a2

File tree

2 files changed

+0
-60
lines changed

2 files changed

+0
-60
lines changed

llvm/lib/Support/CommandLine.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -1667,13 +1667,6 @@ bool CommandLineParser::ParseCommandLineOptions(int argc,
16671667
Handler = LookupLongOption(*ChosenSubCommand, ArgName, Value,
16681668
LongOptionsUseDoubleDash, HaveDoubleDash);
16691669

1670-
// If Handler is not found in a specialized subcommand, look up handler
1671-
// in the top-level subcommand.
1672-
// cl::opt without cl::sub belongs to top-level subcommand.
1673-
if (!Handler && ChosenSubCommand != &SubCommand::getTopLevel())
1674-
Handler = LookupLongOption(SubCommand::getTopLevel(), ArgName, Value,
1675-
LongOptionsUseDoubleDash, HaveDoubleDash);
1676-
16771670
// Check to see if this "option" is really a prefixed or grouped argument.
16781671
if (!Handler && !(LongOptionsUseDoubleDash && HaveDoubleDash))
16791672
Handler = HandlePrefixedOrGroupedOption(ArgName, Value, ErrorParsing,

llvm/unittests/Support/CommandLineTest.cpp

-53
Original file line numberDiff line numberDiff line change
@@ -525,59 +525,6 @@ TEST(CommandLineTest, LookupFailsInWrongSubCommand) {
525525
EXPECT_FALSE(Errs.empty());
526526
}
527527

528-
TEST(CommandLineTest, TopLevelOptInSubcommand) {
529-
enum LiteralOptionEnum {
530-
foo,
531-
bar,
532-
baz,
533-
};
534-
535-
cl::ResetCommandLineParser();
536-
537-
// This is a top-level option and not associated with a subcommand.
538-
// A command line using subcommand should parse both subcommand options and
539-
// top-level options. A valid use case is that users of llvm command line
540-
// tools should be able to specify top-level options defined in any library.
541-
cl::opt<std::string> TopLevelOpt("str", cl::init("txt"),
542-
cl::desc("A top-level option."));
543-
544-
StackSubCommand SC("sc", "Subcommand");
545-
StackOption<std::string> PositionalOpt(
546-
cl::Positional, cl::desc("positional argument test coverage"),
547-
cl::sub(SC));
548-
StackOption<LiteralOptionEnum> LiteralOpt(
549-
cl::desc("literal argument test coverage"), cl::sub(SC), cl::init(bar),
550-
cl::values(clEnumVal(foo, "foo"), clEnumVal(bar, "bar"),
551-
clEnumVal(baz, "baz")));
552-
StackOption<bool> EnableOpt("enable", cl::sub(SC), cl::init(false));
553-
StackOption<int> ThresholdOpt("threshold", cl::sub(SC), cl::init(1));
554-
555-
const char *PositionalOptVal = "input-file";
556-
const char *args[] = {"prog", "sc", PositionalOptVal,
557-
"-enable", "--str=csv", "--threshold=2"};
558-
559-
// cl::ParseCommandLineOptions returns true on success. Otherwise, it will
560-
// print the error message to stderr and exit in this setting (`Errs` ostream
561-
// is not set).
562-
ASSERT_TRUE(cl::ParseCommandLineOptions(sizeof(args) / sizeof(args[0]), args,
563-
StringRef()));
564-
EXPECT_STREQ(PositionalOpt.getValue().c_str(), PositionalOptVal);
565-
EXPECT_TRUE(EnableOpt);
566-
// Tests that the value of `str` option is `csv` as specified.
567-
EXPECT_STREQ(TopLevelOpt.getValue().c_str(), "csv");
568-
EXPECT_EQ(ThresholdOpt, 2);
569-
570-
for (auto &[LiteralOptVal, WantLiteralOpt] :
571-
{std::pair{"--bar", bar}, {"--foo", foo}, {"--baz", baz}}) {
572-
const char *args[] = {"prog", "sc", LiteralOptVal};
573-
ASSERT_TRUE(cl::ParseCommandLineOptions(sizeof(args) / sizeof(args[0]),
574-
args, StringRef()));
575-
576-
// Tests that literal options are parsed correctly.
577-
EXPECT_EQ(LiteralOpt, WantLiteralOpt);
578-
}
579-
}
580-
581528
TEST(CommandLineTest, AddToAllSubCommands) {
582529
cl::ResetCommandLineParser();
583530

0 commit comments

Comments
 (0)