Skip to content

Commit a7d9f4d

Browse files
author
git apple-llvm automerger
committed
Merge commit 'fb7fe49960ae' from llvm.org/main into next
2 parents 2820226 + fb7fe49 commit a7d9f4d

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

llvm/lib/Support/CommandLine.cpp

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,7 @@ class CommandLineParser {
164164
// This collects the different subcommands that have been registered.
165165
SmallPtrSet<SubCommand *, 4> RegisteredSubCommands;
166166

167-
CommandLineParser() {
168-
registerSubCommand(&SubCommand::getTopLevel());
169-
registerSubCommand(&SubCommand::getAll());
170-
}
167+
CommandLineParser() { registerSubCommand(&SubCommand::getTopLevel()); }
171168

172169
void ResetAllOptionOccurrences();
173170

@@ -348,15 +345,15 @@ class CommandLineParser {
348345

349346
// For all options that have been registered for all subcommands, add the
350347
// option to this subcommand now.
351-
if (sub != &SubCommand::getAll()) {
352-
for (auto &E : SubCommand::getAll().OptionsMap) {
353-
Option *O = E.second;
354-
if ((O->isPositional() || O->isSink() || O->isConsumeAfter()) ||
355-
O->hasArgStr())
356-
addOption(O, sub);
357-
else
358-
addLiteralOption(*O, sub, E.first());
359-
}
348+
assert(sub != &SubCommand::getAll() &&
349+
"SubCommand::getAll() should not be registered");
350+
for (auto &E : SubCommand::getAll().OptionsMap) {
351+
Option *O = E.second;
352+
if ((O->isPositional() || O->isSink() || O->isConsumeAfter()) ||
353+
O->hasArgStr())
354+
addOption(O, sub);
355+
else
356+
addLiteralOption(*O, sub, E.first());
360357
}
361358
}
362359

@@ -384,7 +381,6 @@ class CommandLineParser {
384381
SubCommand::getTopLevel().reset();
385382
SubCommand::getAll().reset();
386383
registerSubCommand(&SubCommand::getTopLevel());
387-
registerSubCommand(&SubCommand::getAll());
388384

389385
DefaultOptions.clear();
390386
}
@@ -532,8 +528,8 @@ SubCommand *CommandLineParser::LookupSubCommand(StringRef Name,
532528
// Find a subcommand with the edit distance == 1.
533529
SubCommand *NearestMatch = nullptr;
534530
for (auto *S : RegisteredSubCommands) {
535-
if (S == &SubCommand::getAll())
536-
continue;
531+
assert(S != &SubCommand::getAll() &&
532+
"SubCommand::getAll() is not expected in RegisteredSubCommands");
537533
if (S->getName().empty())
538534
continue;
539535

0 commit comments

Comments
 (0)