[llvm] 5c62190 - [llvm] [CommandLine] Do not suggest really hidden opts in nearest lookup
Michał Górny via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 17 10:01:17 PDT 2020
Author: Michał Górny
Date: 2020-06-17T19:00:26+02:00
New Revision: 5c621900a6614d6e27843c14157b4c2630c124c5
URL: https://github.com/llvm/llvm-project/commit/5c621900a6614d6e27843c14157b4c2630c124c5
DIFF: https://github.com/llvm/llvm-project/commit/5c621900a6614d6e27843c14157b4c2630c124c5.diff
LOG: [llvm] [CommandLine] Do not suggest really hidden opts in nearest lookup
Skip 'really hidden' options when performing lookup of the nearest
option when invalid option was passed. Since these options aren't even
documented in --help-hidden, it seems inconsistent to suggest them
to users.
This fixes clang-tools-extra test failures due to unexpected suggestions
when linking the tools to LLVM dylib (that provides more options than
the subset of LLVM libraries linked directly).
Differential Revision: https://reviews.llvm.org/D82001
Added:
Modified:
llvm/lib/Support/CommandLine.cpp
llvm/unittests/Support/CommandLineTest.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp
index 52053df60818..cee96083f700 100644
--- a/llvm/lib/Support/CommandLine.cpp
+++ b/llvm/lib/Support/CommandLine.cpp
@@ -592,6 +592,10 @@ static Option *LookupNearestOption(StringRef Arg,
ie = OptionsMap.end();
it != ie; ++it) {
Option *O = it->second;
+ // Do not suggest really hidden options (not shown in any help).
+ if (O->getOptionHiddenFlag() == ReallyHidden)
+ continue;
+
SmallVector<StringRef, 16> OptionNames;
O->getExtraOptionNames(OptionNames);
if (O->hasArgStr())
diff --git a/llvm/unittests/Support/CommandLineTest.cpp b/llvm/unittests/Support/CommandLineTest.cpp
index 3e7ec8d5baf1..e1b706e2a78e 100644
--- a/llvm/unittests/Support/CommandLineTest.cpp
+++ b/llvm/unittests/Support/CommandLineTest.cpp
@@ -1735,6 +1735,29 @@ TEST(CommandLineTest, OptionErrorMessageSuggest) {
cl::ResetAllOptionOccurrences();
}
+TEST(CommandLineTest, OptionErrorMessageSuggestNoHidden) {
+ // We expect that 'really hidden' option do not show up in option
+ // suggestions.
+ cl::ResetCommandLineParser();
+
+ StackOption<bool> OptLong("aluminium", cl::desc("Some long option"));
+ StackOption<bool> OptLong2("aluminum", cl::desc("Bad option"),
+ cl::ReallyHidden);
+
+ const char *args[] = {"prog", "--alumnum"};
+
+ std::string Errs;
+ raw_string_ostream OS(Errs);
+
+ EXPECT_FALSE(cl::ParseCommandLineOptions(2, args, StringRef(), &OS));
+ OS.flush();
+ EXPECT_FALSE(Errs.find("prog: Did you mean '--aluminium'?\n") ==
+ std::string::npos);
+ Errs.clear();
+
+ cl::ResetAllOptionOccurrences();
+}
+
TEST(CommandLineTest, Callback) {
cl::ResetCommandLineParser();
More information about the llvm-commits
mailing list