Skip to content

Commit

Permalink
Add typo correction for command-line flags to ELF and COFF lld drivers
Browse files Browse the repository at this point in the history
For lld-link, unknown '/'-style flags are treated as filenames on POSIX
systems, so only '-'-style flags get typo correction for now. This
matches clang-cl.

PR37006.

Differential Revision: https://reviews.llvm.org/D61443

llvm-svn: 360145
  • Loading branch information
nico authored and MrSidims committed May 17, 2019
1 parent ef73458 commit 061b8e3
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 11 deletions.
10 changes: 8 additions & 2 deletions lld/COFF/DriverUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -858,8 +858,14 @@ opt::InputArgList ArgParser::parse(ArrayRef<const char *> 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");
Expand Down
10 changes: 8 additions & 2 deletions lld/ELF/DriverUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,14 @@ opt::InputArgList ELFOptTable::parse(ArrayRef<const char *> 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;
}

Expand Down
2 changes: 1 addition & 1 deletion lld/test/COFF/color-diagnostics.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions lld/test/COFF/driver.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions lld/test/COFF/wx.s
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lld/test/ELF/basic.s
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lld/test/ELF/color-diagnostics.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions lld/test/ELF/driver.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 061b8e3

Please sign in to comment.