summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2017-03-13 22:19:05 +0000
committerRui Ueyama <ruiu@google.com>2017-03-13 22:19:05 +0000
commitfed8b570b7c50f1c36e4252dac60fe4a12f64045 (patch)
tree6d3613bae9261126c26dea0dbe5309d714046843
parent784f241b59ebe005fbfeb3f1adb42c7d423ae166 (diff)
downloadbcm5719-llvm-fed8b570b7c50f1c36e4252dac60fe4a12f64045.tar.gz
bcm5719-llvm-fed8b570b7c50f1c36e4252dac60fe4a12f64045.zip
Make FileOutputBuffer fail early if you pass a directory.
Previously, it created a temporary directory and then failed when FileOutputBuffer tried to rename that file to the destination file (which is actually a directory name). Differential Revision: https://reviews.llvm.org/D30912 llvm-svn: 297679
-rw-r--r--lld/test/ELF/early-exit-for-bad-paths.s3
-rw-r--r--llvm/lib/Support/FileOutputBuffer.cpp2
2 files changed, 5 insertions, 0 deletions
diff --git a/lld/test/ELF/early-exit-for-bad-paths.s b/lld/test/ELF/early-exit-for-bad-paths.s
index aa737342bf9..856d48ba21e 100644
--- a/lld/test/ELF/early-exit-for-bad-paths.s
+++ b/lld/test/ELF/early-exit-for-bad-paths.s
@@ -20,6 +20,9 @@
# discovered we haven't bailed out early as expected.
# CHECK-NOT: undefined_symbol
+# RUN: not ld.lld %t.o -o / 2>&1 | FileCheck %s -check-prefixes=ROOT
+# ROOT: error: cannot open output file /
+
.globl _start
_start:
call undefined_symbol
diff --git a/llvm/lib/Support/FileOutputBuffer.cpp b/llvm/lib/Support/FileOutputBuffer.cpp
index 57e5a8d7871..731740d012d 100644
--- a/llvm/lib/Support/FileOutputBuffer.cpp
+++ b/llvm/lib/Support/FileOutputBuffer.cpp
@@ -57,6 +57,8 @@ FileOutputBuffer::create(StringRef FilePath, size_t Size, unsigned Flags) {
// FIXME: In posix, you use the access() call to check this.
}
break;
+ case sys::fs::file_type::directory_file:
+ return errc::is_a_directory;
default:
if (EC)
return EC;
OpenPOWER on IntegriCloud