Skip to content

Commit 37bf9bb

Browse files
committed
Use error instead of fatal to report usage errors
Differential Revision: https://reviews.llvm.org/D68768 llvm-svn: 374297
1 parent 9d9ac46 commit 37bf9bb

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

lld/MinGW/Driver.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ opt::InputArgList MinGWOptTable::parse(ArrayRef<const char *> argv) {
103103
opt::InputArgList args = this->ParseArgs(vec, missingIndex, missingCount);
104104

105105
if (missingCount)
106-
fatal(StringRef(args.getArgString(missingIndex)) + ": missing argument");
106+
error(StringRef(args.getArgString(missingIndex)) + ": missing argument");
107107
for (auto *arg : args.filtered(OPT_UNKNOWN))
108-
fatal("unknown argument: " + arg->getAsString(args));
108+
error("unknown argument: " + arg->getAsString(args));
109109
return args;
110110
}
111111

@@ -160,9 +160,14 @@ searchLibrary(StringRef name, ArrayRef<StringRef> searchPaths, bool bStatic) {
160160
// Convert Unix-ish command line arguments to Windows-ish ones and
161161
// then call coff::link.
162162
bool mingw::link(ArrayRef<const char *> argsArr, raw_ostream &diag) {
163+
enableColors(diag.has_colors());
164+
163165
MinGWOptTable parser;
164166
opt::InputArgList args = parser.parse(argsArr.slice(1));
165167

168+
if (errorCount())
169+
return false;
170+
166171
if (args.hasArg(OPT_help)) {
167172
printHelp(argsArr[0]);
168173
return true;
@@ -183,8 +188,10 @@ bool mingw::link(ArrayRef<const char *> argsArr, raw_ostream &diag) {
183188
if (args.hasArg(OPT_version))
184189
return true;
185190

186-
if (!args.hasArg(OPT_INPUT) && !args.hasArg(OPT_l))
187-
fatal("no input files");
191+
if (!args.hasArg(OPT_INPUT) && !args.hasArg(OPT_l)) {
192+
error("no input files");
193+
return false;
194+
}
188195

189196
std::vector<std::string> linkArgs;
190197
auto add = [&](const Twine &s) { linkArgs.push_back(s.str()); };
@@ -290,7 +297,7 @@ bool mingw::link(ArrayRef<const char *> argsArr, raw_ostream &diag) {
290297
else if (s == "safe" || s == "none")
291298
add("-opt:noicf");
292299
else
293-
fatal("unknown parameter: --icf=" + s);
300+
error("unknown parameter: --icf=" + s);
294301
} else {
295302
add("-opt:noicf");
296303
}
@@ -306,7 +313,7 @@ bool mingw::link(ArrayRef<const char *> argsArr, raw_ostream &diag) {
306313
else if (s == "arm64pe")
307314
add("-machine:arm64");
308315
else
309-
fatal("unknown parameter: -m" + s);
316+
error("unknown parameter: -m" + s);
310317
}
311318

312319
for (auto *a : args.filtered(OPT_mllvm))

lld/test/MinGW/driver.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,12 @@ HELP: --enable-auto-import
214214
RUN: ld.lld -### -m i386pep foo.o -delayload user32.dll --delayload shell32.dll | FileCheck -check-prefix DELAYLOAD %s
215215
RUN: ld.lld -### -m i386pep foo.o -delayload=user32.dll --delayload=shell32.dll | FileCheck -check-prefix DELAYLOAD %s
216216
DELAYLOAD: -delayload:user32.dll -delayload:shell32.dll
217+
218+
RUN: not ld.lld -m i386pep -entry 2>&1 | FileCheck -check-prefix MISSING_ARG %s
219+
MISSING_ARG: error: -entry: missing argument
220+
221+
RUN: not ld.lld -m i386pep --foo 2>&1 | FileCheck -check-prefix UNKNOWN_ARG %s
222+
UNKNOWN_ARG: error: unknown argument: --foo
223+
224+
RUN: not ld.lld -m i386pep 2>&1 | FileCheck -check-prefix NO_INPUT_FILES %s
225+
NO_INPUT_FILES: error: no input files

0 commit comments

Comments
 (0)