diff --git a/llvm/include/llvm/Option/OptTable.h b/llvm/include/llvm/Option/OptTable.h --- a/llvm/include/llvm/Option/OptTable.h +++ b/llvm/include/llvm/Option/OptTable.h @@ -248,7 +248,8 @@ StringSaver &Saver, function_ref ErrorFn) const; - /// Render the help text for an option table. + /// Render the help text for an option table. Render options with and without + /// help texts. /// /// \param OS - The stream to write the help text to. /// \param Usage - USAGE: Usage @@ -256,10 +257,8 @@ /// \param FlagsToInclude - If non-zero, only include options with any /// of these flags set. /// \param FlagsToExclude - Exclude options with any of these flags set. - /// \param ShowAllAliases - If true, display all options including aliases - /// that don't have help texts. By default, we display - /// only options that are not hidden and have help - /// texts. + /// \param ShowAllAliases - If false, hide aliases, that do not have their + /// own help text. void printHelp(raw_ostream &OS, const char *Usage, const char *Title, unsigned FlagsToInclude, unsigned FlagsToExclude, bool ShowAllAliases) const; diff --git a/llvm/lib/Option/OptTable.cpp b/llvm/lib/Option/OptTable.cpp --- a/llvm/lib/Option/OptTable.cpp +++ b/llvm/lib/Option/OptTable.cpp @@ -598,6 +598,11 @@ int Pad = OptionFieldWidth - int(Option.size()); OS.indent(InitialPad) << Option; + if (Opt.HelpText.empty()) { + OS << '\n'; + continue; + } + // Break on long option names. if (Pad < 0) { OS << "\n"; @@ -643,7 +648,9 @@ for (unsigned Id = 1, e = getNumOptions() + 1; Id != e; ++Id) { // FIXME: Split out option groups. - if (getOptionKind(Id) == Option::GroupClass) + auto Kind = getOptionKind(Id); + if (Kind == Option::GroupClass || Kind == Option::InputClass || + Kind == Option::UnknownClass) continue; unsigned Flags = getInfo(Id).Flags; @@ -655,17 +662,18 @@ // If an alias doesn't have a help text, show a help text for the aliased // option instead. const char *HelpText = getOptionHelpText(Id); - if (!HelpText && ShowAllAliases) { + if (!HelpText) { const Option Alias = getOption(Id).getAlias(); - if (Alias.isValid()) + if (Alias.isValid()) { + if (!ShowAllAliases) + continue; HelpText = getOptionHelpText(Alias.getID()); + } } - if (HelpText && (strlen(HelpText) != 0)) { - const char *HelpGroup = getOptionHelpGroup(*this, Id); - const std::string &OptName = getOptionHelpName(*this, Id); - GroupedOptionHelp[HelpGroup].push_back({OptName, HelpText}); - } + const char *HelpGroup = getOptionHelpGroup(*this, Id); + const std::string &OptName = getOptionHelpName(*this, Id); + GroupedOptionHelp[HelpGroup].push_back({OptName, HelpText}); } for (auto& OptionGroup : GroupedOptionHelp) {