Skip to content

Commit d85a13b

Browse files
committed
Revert "[CommandLine][NFCI] Do not add 'All' to 'RegisteredSubCommands' (#77041)"
This reverts commit fb7fe49. The commit introduced a bug where an option with the `All' subcommand would not be added to a category initialized after that option.
1 parent 31fd6d1 commit d85a13b

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

llvm/lib/Support/CommandLine.cpp

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

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

169172
void ResetAllOptionOccurrences();
170173

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

346349
// For all options that have been registered for all subcommands, add the
347350
// option to this subcommand now.
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());
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+
}
357360
}
358361
}
359362

@@ -381,6 +384,7 @@ class CommandLineParser {
381384
SubCommand::getTopLevel().reset();
382385
SubCommand::getAll().reset();
383386
registerSubCommand(&SubCommand::getTopLevel());
387+
registerSubCommand(&SubCommand::getAll());
384388

385389
DefaultOptions.clear();
386390
}
@@ -528,8 +532,8 @@ SubCommand *CommandLineParser::LookupSubCommand(StringRef Name,
528532
// Find a subcommand with the edit distance == 1.
529533
SubCommand *NearestMatch = nullptr;
530534
for (auto *S : RegisteredSubCommands) {
531-
assert(S != &SubCommand::getAll() &&
532-
"SubCommand::getAll() is not expected in RegisteredSubCommands");
535+
if (S == &SubCommand::getAll())
536+
continue;
533537
if (S->getName().empty())
534538
continue;
535539

0 commit comments

Comments
 (0)