diff --git a/lld/COFF/DriverUtils.cpp b/lld/COFF/DriverUtils.cpp index bd7381890e60..4a99cd6f2e83 100644 --- a/lld/COFF/DriverUtils.cpp +++ b/lld/COFF/DriverUtils.cpp @@ -858,8 +858,14 @@ opt::InputArgList ArgParser::parse(ArrayRef Argv) { handleColorDiagnostics(Args); - for (auto *Arg : Args.filtered(OPT_UNKNOWN)) - warn("ignoring unknown argument: " + Arg->getSpelling()); + for (auto *Arg : Args.filtered(OPT_UNKNOWN)) { + std::string Nearest; + if (Table.findNearest(Arg->getAsString(Args), Nearest) > 1) + warn("ignoring unknown argument '" + Arg->getSpelling() + "'"); + else + warn("ignoring unknown argument '" + Arg->getSpelling() + + "', did you mean '" + Nearest + "'"); + } if (Args.hasArg(OPT_lib)) warn("ignoring /lib since it's not the first argument"); diff --git a/lld/ELF/DriverUtils.cpp b/lld/ELF/DriverUtils.cpp index 3d62dd54d4ac..0fb3aebc61f2 100644 --- a/lld/ELF/DriverUtils.cpp +++ b/lld/ELF/DriverUtils.cpp @@ -132,8 +132,14 @@ opt::InputArgList ELFOptTable::parse(ArrayRef Argv) { if (MissingCount) error(Twine(Args.getArgString(MissingIndex)) + ": missing argument"); - for (auto *Arg : Args.filtered(OPT_UNKNOWN)) - error("unknown argument: " + Arg->getSpelling()); + for (auto *Arg : Args.filtered(OPT_UNKNOWN)) { + std::string Nearest; + if (findNearest(Arg->getAsString(Args), Nearest) > 1) + error("unknown argument '" + Arg->getSpelling() + "'"); + else + error("unknown argument '" + Arg->getSpelling() + "', did you mean '" + + Nearest + "'"); + } return Args; } diff --git a/lld/test/COFF/color-diagnostics.test b/lld/test/COFF/color-diagnostics.test index a231f1fcf4e2..9cb145a335ef 100644 --- a/lld/test/COFF/color-diagnostics.test +++ b/lld/test/COFF/color-diagnostics.test @@ -6,7 +6,7 @@ # RUN: not lld-link -xyz --color-diagnostics=always /nosuchfile 2>&1 \ # RUN: | FileCheck -check-prefix=COLOR %s -# COLOR: {{lld-link: .\[0;1;35mwarning: .\[0mignoring unknown argument: -xyz}} +# COLOR: {{lld-link: .\[0;1;35mwarning: .\[0mignoring unknown argument '-xyz'}} # COLOR: {{lld-link: .\[0;1;31merror: .\[0mcould not open /nosuchfile}} # RUN: not lld-link /nosuchfile 2>&1 | FileCheck -check-prefix=NOCOLOR %s diff --git a/lld/test/COFF/driver.test b/lld/test/COFF/driver.test index 50aa91b7e7d9..f4d0e6ae1c90 100644 --- a/lld/test/COFF/driver.test +++ b/lld/test/COFF/driver.test @@ -19,3 +19,11 @@ LIBBAD: ignoring /lib since it's not the first argument # RUN: yaml2obj < %p/Inputs/hello32.yaml > %t.obj # RUN: not lld-link /out:/ %t.obj 2>&1 | FileCheck -check-prefix=DIR %s DIR: cannot open output file + +# RUN: not lld-link -version 2>&1 | FileCheck -check-prefix=SPELLVERSION %s +SPELLVERSION: ignoring unknown argument '-version', did you mean '--version' +SPELLVERSION: no input files + +# RUN: not lld-link -nodefaultlibs 2>&1 | FileCheck -check-prefix=SPELLNODEFAULTLIB %s +SPELLNODEFAULTLIB: ignoring unknown argument '-nodefaultlibs', did you mean '-nodefaultlib' +SPELLNODEFAULTLIB: no input files diff --git a/lld/test/COFF/wx.s b/lld/test/COFF/wx.s index 3a470edc261c..2b9dbbc21e51 100644 --- a/lld/test/COFF/wx.s +++ b/lld/test/COFF/wx.s @@ -8,8 +8,8 @@ # RUN: lld-link /out:%t.exe /entry:main -notarealoption /WX /WX:NO %t.obj 2>&1 | \ # RUN: FileCheck -check-prefix=WARNING %s -# ERROR: error: ignoring unknown argument: -notarealoption -# WARNING: warning: ignoring unknown argument: -notarealoption +# ERROR: error: ignoring unknown argument '-notarealoption' +# WARNING: warning: ignoring unknown argument '-notarealoption' .text .global main diff --git a/lld/test/ELF/basic.s b/lld/test/ELF/basic.s index b20e6c6e04d0..11570be6832a 100644 --- a/lld/test/ELF/basic.s +++ b/lld/test/ELF/basic.s @@ -234,7 +234,7 @@ _start: # NO_O_VAL: -o: missing argument # RUN: not ld.lld --foo 2>&1 | FileCheck --check-prefix=UNKNOWN %s -# UNKNOWN: unknown argument: --foo +# UNKNOWN: unknown argument '--foo' # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t # RUN: not ld.lld %t %t -o %t2 2>&1 | FileCheck --check-prefix=DUP %s diff --git a/lld/test/ELF/color-diagnostics.test b/lld/test/ELF/color-diagnostics.test index 6dfa0ab1af92..8613074dc565 100644 --- a/lld/test/ELF/color-diagnostics.test +++ b/lld/test/ELF/color-diagnostics.test @@ -6,7 +6,7 @@ # RUN: not ld.lld -xyz -color-diagnostics=always /nosuchfile 2>&1 \ # RUN: | FileCheck -check-prefix=COLOR %s -# COLOR: {{ld.lld: .\[0;1;31merror: .\[0munknown argument: -xyz}} +# COLOR: {{ld.lld: .\[0;1;31merror: .\[0munknown argument '-xyz'}} # COLOR: {{ld.lld: .\[0;1;31merror: .\[0mcannot open /nosuchfile}} # RUN: not ld.lld -color-diagnostics=foobar 2>&1 | FileCheck -check-prefix=ERR %s diff --git a/lld/test/ELF/driver.test b/lld/test/ELF/driver.test index cc3e7898f09b..29a06171c3d7 100644 --- a/lld/test/ELF/driver.test +++ b/lld/test/ELF/driver.test @@ -3,8 +3,8 @@ # RUN: not ld.lld --unknown1 --unknown2 -m foo /no/such/file -lnosuchlib \ # RUN: 2>&1 | FileCheck -check-prefix=UNKNOWN %s -# UNKNOWN: unknown argument: --unknown1 -# UNKNOWN: unknown argument: --unknown2 +# UNKNOWN: unknown argument '--unknown1' +# UNKNOWN: unknown argument '--unknown2' # UNKNOWN: unknown emulation: foo # UNKNOWN: cannot open /no/such/file # UNKNOWN: unable to find library -lnosuchlib @@ -22,6 +22,9 @@ # RUN: not ld.lld -v xyz 2>&1 | FileCheck -check-prefix=VERSION %s # VERSION: LLD {{.*}} (compatible with GNU linkers) +# RUN: not ld.lld --versin 2>&1 | FileCheck -check-prefix=SPELLVERSION %s +# SPELLVERSION: unknown argument '--versin', did you mean '--version' + ## Attempt to link DSO with -r # RUN: ld.lld -shared %t -o %t.so # RUN: not ld.lld -r %t.so %t -o %tfail 2>&1 | FileCheck -check-prefix=ERR %s