summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/test/tools/llvm-objcopy/fail-no-output-directory.test11
-rw-r--r--llvm/tools/llvm-objcopy/llvm-objcopy.cpp7
2 files changed, 15 insertions, 3 deletions
diff --git a/llvm/test/tools/llvm-objcopy/fail-no-output-directory.test b/llvm/test/tools/llvm-objcopy/fail-no-output-directory.test
new file mode 100644
index 00000000000..89bf62d3556
--- /dev/null
+++ b/llvm/test/tools/llvm-objcopy/fail-no-output-directory.test
@@ -0,0 +1,11 @@
+# RUN: yaml2obj %s > %t
+# RUN: not llvm-objcopy %t no/such/dir 2>&1 | FileCheck %s
+# CHECK: failed to open no/such/dir
+
+!ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_X86_64
+
diff --git a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
index c923f902db8..54186f63c07 100644
--- a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
+++ b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
@@ -116,10 +116,11 @@ void WriteObjectFile(const Object<ELFT> &Obj, StringRef File) {
Expected<std::unique_ptr<FileOutputBuffer>> BufferOrErr =
FileOutputBuffer::create(File, Obj.totalSize(),
FileOutputBuffer::F_executable);
- if (BufferOrErr.takeError())
+ handleAllErrors(BufferOrErr.takeError(), [](const ErrorInfoBase &) {
error("failed to open " + OutputFilename);
- else
- Buffer = std::move(*BufferOrErr);
+ });
+ Buffer = std::move(*BufferOrErr);
+
Obj.write(*Buffer);
if (auto E = Buffer->commit())
reportError(File, errorToErrorCode(std::move(E)));
OpenPOWER on IntegriCloud