Index: COFF/DriverUtils.cpp =================================================================== --- COFF/DriverUtils.cpp +++ COFF/DriverUtils.cpp @@ -858,8 +858,14 @@ 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"); Index: ELF/DriverUtils.cpp =================================================================== --- ELF/DriverUtils.cpp +++ ELF/DriverUtils.cpp @@ -132,8 +132,14 @@ 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; } Index: test/COFF/color-diagnostics.test =================================================================== --- test/COFF/color-diagnostics.test +++ 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 Index: test/COFF/driver.test =================================================================== --- test/COFF/driver.test +++ test/COFF/driver.test @@ -19,3 +19,11 @@ # 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 Index: test/COFF/wx.s =================================================================== --- test/COFF/wx.s +++ 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 Index: test/ELF/basic.s =================================================================== --- test/ELF/basic.s +++ test/ELF/basic.s @@ -234,7 +234,7 @@ # 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 Index: test/ELF/color-diagnostics.test =================================================================== --- test/ELF/color-diagnostics.test +++ 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 Index: test/ELF/driver.test =================================================================== --- test/ELF/driver.test +++ 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