summaryrefslogtreecommitdiffstats
path: root/clang/lib/Frontend/CompilerInvocation.cpp
diff options
context:
space:
mode:
authorBrian Gesiak <modocache@gmail.com>2018-01-06 00:25:40 +0000
committerBrian Gesiak <modocache@gmail.com>2018-01-06 00:25:40 +0000
commit24910765e266a4344fa2993a2c5f3fdd9bfb19eb (patch)
treea034946598a9f85cfad2bdf4f20e80aaa997b2e0 /clang/lib/Frontend/CompilerInvocation.cpp
parent041740ff69b1a7d0393f511c52587274cc3abd0a (diff)
downloadbcm5719-llvm-24910765e266a4344fa2993a2c5f3fdd9bfb19eb.tar.gz
bcm5719-llvm-24910765e266a4344fa2993a2c5f3fdd9bfb19eb.zip
[Driver] Suggest correctly spelled driver options
Summary: Depends on https://reviews.llvm.org/D41732. Utilities such as `opt`, when invoked with arguments that are very nearly spelled correctly, suggest the correctly spelled options: ``` bin/opt -hel opt: Unknown command line argument '-hel'. Try: 'bin/opt -help' opt: Did you mean '-help'? ``` Clang, on the other hand, prior to this commit, does not: ``` bin/clang -hel clang-6.0: error: unknown argument: '-hel' ``` This commit makes use of the new libLLVMOption API from https://reviews.llvm.org/D41732 in order to provide correct suggestions: ``` bin/clang -hel clang-6.0: error: unknown argument: '-hel', did you mean '-help'? ``` Test Plan: `check-clang` Reviewers: yamaguchi, v.g.vassilev, teemperor, ruiu, bruno Reviewed By: bruno Subscribers: bruno, jroelofs, cfe-commits Differential Revision: https://reviews.llvm.org/D41733 llvm-svn: 321917
Diffstat (limited to 'clang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r--clang/lib/Frontend/CompilerInvocation.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 6ce719aac67..ce875fa03b9 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2757,7 +2757,13 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
// Issue errors on unknown arguments.
for (const Arg *A : Args.filtered(OPT_UNKNOWN)) {
- Diags.Report(diag::err_drv_unknown_argument) << A->getAsString(Args);
+ auto ArgString = A->getAsString(Args);
+ std::string Nearest;
+ if (Opts->findNearest(ArgString, Nearest, IncludedFlagsBitmask) > 1)
+ Diags.Report(diag::err_drv_unknown_argument) << ArgString;
+ else
+ Diags.Report(diag::err_drv_unknown_argument_with_suggestion)
+ << ArgString << Nearest;
Success = false;
}
OpenPOWER on IntegriCloud