lld, llvm-dlltool, llvm-lib: Use getAsString() instead of getSpelling() for printing unknown args

Since OPT_UNKNOWN args never have any values and consist only of
spelling (and are never aliased), this doesn't make any difference in
practice, but it's more consistent with Arg's guidance to use
getAsString() for diagnostics, and it matches what clang does.

Also tweak two tests to use an unknown option that contains '=' for
additional coverage while here. (The new tests pass fine with the old
code too though.)

llvm-svn: 365200
This commit is contained in:
Nico Weber 2019-07-05 12:31:32 +00:00
parent 2478b62098
commit a780276301
8 changed files with 19 additions and 17 deletions

View File

@ -826,9 +826,9 @@ opt::InputArgList ArgParser::parse(ArrayRef<const char *> Argv) {
for (auto *Arg : Args.filtered(OPT_UNKNOWN)) {
std::string Nearest;
if (Table.findNearest(Arg->getAsString(Args), Nearest) > 1)
warn("ignoring unknown argument '" + Arg->getSpelling() + "'");
warn("ignoring unknown argument '" + Arg->getAsString(Args) + "'");
else
warn("ignoring unknown argument '" + Arg->getSpelling() +
warn("ignoring unknown argument '" + Arg->getAsString(Args) +
"', did you mean '" + Nearest + "'");
}
@ -861,7 +861,7 @@ ArgParser::parseDirectives(StringRef S) {
if (MissingCount)
fatal(Twine(Args.getArgString(MissingIndex)) + ": missing argument");
for (auto *Arg : Args.filtered(OPT_UNKNOWN))
warn("ignoring unknown argument: " + Arg->getSpelling());
warn("ignoring unknown argument: " + Arg->getAsString(Args));
return {std::move(Args), std::move(Exports)};
}

View File

@ -135,10 +135,10 @@ opt::InputArgList ELFOptTable::parse(ArrayRef<const char *> Argv) {
for (auto *Arg : Args.filtered(OPT_UNKNOWN)) {
std::string Nearest;
if (findNearest(Arg->getAsString(Args), Nearest) > 1)
error("unknown argument '" + Arg->getSpelling() + "'");
error("unknown argument '" + Arg->getAsString(Args) + "'");
else
error("unknown argument '" + Arg->getSpelling() + "', did you mean '" +
Nearest + "'");
error("unknown argument '" + Arg->getAsString(Args) +
"', did you mean '" + Nearest + "'");
}
return Args;
}

View File

@ -105,7 +105,7 @@ opt::InputArgList MinGWOptTable::parse(ArrayRef<const char *> Argv) {
if (MissingCount)
fatal(StringRef(Args.getArgString(MissingIndex)) + ": missing argument");
for (auto *Arg : Args.filtered(OPT_UNKNOWN))
fatal("unknown argument: " + Arg->getSpelling());
fatal("unknown argument: " + Arg->getAsString(Args));
return Args;
}

View File

@ -1,15 +1,15 @@
# REQUIRES: x86
# RUN: llvm-mc -triple=x86_64-windows-msvc -filetype=obj -o %t.obj %s
# RUN: not lld-link /out:%t.exe /entry:main -notarealoption /WX %t.obj 2>&1 | \
# RUN: not lld-link /out:%t.exe /entry:main -notarealopt=ion /WX %t.obj 2>&1 | \
# RUN: FileCheck -check-prefix=ERROR %s
# RUN: not lld-link /out:%t.exe /entry:main -notarealoption /WX:NO /WX %t.obj 2>&1 | \
# RUN: not lld-link /out:%t.exe /entry:main -notarealopt=ion /WX:NO /WX %t.obj 2>&1 | \
# RUN: FileCheck -check-prefix=ERROR %s
# RUN: lld-link /out:%t.exe /entry:main -notarealoption /WX /WX:NO %t.obj 2>&1 | \
# RUN: lld-link /out:%t.exe /entry:main -notarealopt=ion /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 '-notarealopt=ion'
# WARNING: warning: ignoring unknown argument '-notarealopt=ion'
.text
.global main

View File

@ -1,10 +1,10 @@
# REQUIRES: x86
# RUN: not ld.lld --unknown1 --unknown2 -m foo /no/such/file -lnosuchlib \
# RUN: not ld.lld --unknown1 --unkn=own2 -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 '--unkn=own2'
# UNKNOWN: unknown emulation: foo
# UNKNOWN: cannot open /no/such/file
# UNKNOWN: unable to find library -lnosuchlib

View File

@ -170,7 +170,7 @@ opt::InputArgList WasmOptTable::parse(ArrayRef<const char *> Argv) {
handleColorDiagnostics(Args);
for (auto *Arg : Args.filtered(OPT_UNKNOWN))
error("unknown argument: " + Arg->getSpelling());
error("unknown argument: " + Arg->getAsString(Args));
return Args;
}

View File

@ -108,7 +108,8 @@ int llvm::dlltoolDriverMain(llvm::ArrayRef<const char *> ArgsArr) {
}
for (auto *Arg : Args.filtered(OPT_UNKNOWN))
llvm::errs() << "ignoring unknown argument: " << Arg->getSpelling() << "\n";
llvm::errs() << "ignoring unknown argument: " << Arg->getAsString(Args)
<< "\n";
if (!Args.hasArg(OPT_d)) {
llvm::errs() << "no definition file specified\n";

View File

@ -163,7 +163,8 @@ int llvm::libDriverMain(ArrayRef<const char *> ArgsArr) {
return 1;
}
for (auto *Arg : Args.filtered(OPT_UNKNOWN))
llvm::errs() << "ignoring unknown argument: " << Arg->getSpelling() << "\n";
llvm::errs() << "ignoring unknown argument: " << Arg->getAsString(Args)
<< "\n";
// Handle /help
if (Args.hasArg(OPT_help)) {