[lld] r217359 - [ELF][Driver] Produce a proper error when file is not found
Shankar Easwaran
shankarke at gmail.com
Sun Sep 7 21:18:11 PDT 2014
Author: shankare
Date: Sun Sep 7 23:18:11 2014
New Revision: 217359
URL: http://llvm.org/viewvc/llvm-project?rev=217359&view=rev
Log:
[ELF][Driver] Produce a proper error when file is not found
When a file is not found, produce a proper error message. The previous error
message produced a file format error, which made me wonder for a while why
there is a file format error, but essentially the file was not found.
This fixes the problem by producing a proper error message.
Added:
lld/trunk/test/elf/filenotfound.test
Modified:
lld/trunk/lib/Driver/GnuLdDriver.cpp
Modified: lld/trunk/lib/Driver/GnuLdDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/GnuLdDriver.cpp?rev=217359&r1=217358&r2=217359&view=diff
==============================================================================
--- lld/trunk/lib/Driver/GnuLdDriver.cpp (original)
+++ lld/trunk/lib/Driver/GnuLdDriver.cpp Sun Sep 7 23:18:11 2014
@@ -488,6 +488,10 @@ bool GnuLdDriver::parse(int argc, const
// FIXME: Calling getFileMagic() is expensive. It would be better to
// wire up the LdScript parser into the registry.
llvm::sys::fs::file_magic magic = llvm::sys::fs::file_magic::unknown;
+ if (!llvm::sys::fs::exists(resolvedInputPath)) {
+ diagnostics << "lld: cannot find file " << userPath << "\n";
+ return false;
+ }
std::error_code ec = getFileMagic(*ctx, resolvedInputPath, magic);
if (ec) {
diagnostics << "lld: unknown input file format for file " << userPath
Added: lld/trunk/test/elf/filenotfound.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/filenotfound.test?rev=217359&view=auto
==============================================================================
--- lld/trunk/test/elf/filenotfound.test (added)
+++ lld/trunk/test/elf/filenotfound.test Sun Sep 7 23:18:11 2014
@@ -0,0 +1,3 @@
+# Check that a file that cannot be found results in a proper error message
+RUN: not lld -flavor gnu -target x86_64 %p/Inputs/nofile.o 2>&1 | FileCheck %s
+#CHECK: lld: cannot find file {{[-_A-Za-z0-9.\\/:]+}}nofile.o
More information about the llvm-commits
mailing list