From: Nico Weber Date: Mon, 23 Nov 2020 15:51:56 +0000 (-0500) Subject: [lld/mac] Implement basic typo correction for flags X-Git-Tag: llvmorg-13-init~5246 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=11b76258331659daa57e15fe86c1f1234267a78d;p=platform%2Fupstream%2Fllvm.git [lld/mac] Implement basic typo correction for flags Also use "unknown flag 'flag'" instead of "unknown flag: flag" for consistency with the other ports. Differential Revision: https://reviews.llvm.org/D91970 --- diff --git a/lld/COFF/DriverUtils.cpp b/lld/COFF/DriverUtils.cpp index 7de73f2..f289e66 100644 --- a/lld/COFF/DriverUtils.cpp +++ b/lld/COFF/DriverUtils.cpp @@ -852,7 +852,7 @@ opt::InputArgList ArgParser::parse(ArrayRef argv) { handleColorDiagnostics(args); - for (auto *arg : args.filtered(OPT_UNKNOWN)) { + for (opt::Arg *arg : args.filtered(OPT_UNKNOWN)) { std::string nearest; if (optTable.findNearest(arg->getAsString(args), nearest) > 1) warn("ignoring unknown argument '" + arg->getAsString(args) + "'"); diff --git a/lld/ELF/DriverUtils.cpp b/lld/ELF/DriverUtils.cpp index 0317356..8ce9853 100644 --- a/lld/ELF/DriverUtils.cpp +++ b/lld/ELF/DriverUtils.cpp @@ -133,7 +133,7 @@ opt::InputArgList ELFOptTable::parse(ArrayRef argv) { if (missingCount) error(Twine(args.getArgString(missingIndex)) + ": missing argument"); - for (auto *arg : args.filtered(OPT_UNKNOWN)) { + for (opt::Arg *arg : args.filtered(OPT_UNKNOWN)) { std::string nearest; if (findNearest(arg->getAsString(args), nearest) > 1) error("unknown argument '" + arg->getAsString(args) + "'"); diff --git a/lld/MachO/DriverUtils.cpp b/lld/MachO/DriverUtils.cpp index 3899348..0322c20 100644 --- a/lld/MachO/DriverUtils.cpp +++ b/lld/MachO/DriverUtils.cpp @@ -75,8 +75,14 @@ opt::InputArgList MachOOptTable::parse(ArrayRef argv) { handleColorDiagnostics(args); - for (opt::Arg *arg : args.filtered(OPT_UNKNOWN)) - error("unknown argument: " + arg->getSpelling()); + for (opt::Arg *arg : args.filtered(OPT_UNKNOWN)) { + std::string nearest; + if (findNearest(arg->getAsString(args), nearest) > 1) + error("unknown argument '" + arg->getAsString(args) + "'"); + else + error("unknown argument '" + arg->getAsString(args) + + "', did you mean '" + nearest + "'"); + } return args; } diff --git a/lld/test/MachO/color-diagnostics.test b/lld/test/MachO/color-diagnostics.test index 3bf757b..b3c496f 100644 --- a/lld/test/MachO/color-diagnostics.test +++ b/lld/test/MachO/color-diagnostics.test @@ -6,7 +6,7 @@ # RUN: not %lld -xyz --color-diagnostics=always /nosuchfile 2>&1 \ # RUN: | FileCheck -check-prefix=COLOR %s -# COLOR: {{lld: .\[0;31merror: .\[0munknown argument: -xyz}} +# COLOR: {{lld: .\[0;31merror: .\[0munknown argument '-xyz'}} # COLOR: {{lld: .\[0;31merror: .\[0mcannot open /nosuchfile}} # RUN: not %lld --color-diagnostics=foobar 2>&1 | FileCheck -check-prefix=ERR %s diff --git a/lld/test/MachO/driver.test b/lld/test/MachO/driver.test new file mode 100644 index 0000000..229ec3e --- /dev/null +++ b/lld/test/MachO/driver.test @@ -0,0 +1,5 @@ +# RUN: not %lld ---help 2>&1 | FileCheck -check-prefix=SPELLHELP %s + +SPELLHELP: error: unknown argument '---help', did you mean '--help' +# FIXME: This should say "no input files" instead +SPELLHELP: error: undefined symbol: _main diff --git a/lld/test/MachO/silent-ignore.test b/lld/test/MachO/silent-ignore.test index cac6660..2d11748 100644 --- a/lld/test/MachO/silent-ignore.test +++ b/lld/test/MachO/silent-ignore.test @@ -9,4 +9,4 @@ RUN: -objc_abi_version 2 \ RUN: -ios_simulator_version_min 9.0.0 \ RUN: -sdk_version 13.2 RUN: not %lld -v --not-an-ignored-argument 2>&1 | FileCheck %s -CHECK: error: unknown argument: --not-an-ignored-argument +CHECK: error: unknown argument '--not-an-ignored-argument'