[PATCH] D56949: FileOutputBuffer: handle mmap(2) failure
Rui Ueyama via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 22 13:51:59 PST 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rL351883: FileOutputBuffer: handle mmap(2) failure (authored by ruiu, committed by ).
Herald added a subscriber: kristina.
Changed prior to commit:
https://reviews.llvm.org/D56949?vs=182645&id=182977#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D56949/new/
https://reviews.llvm.org/D56949
Files:
llvm/trunk/lib/Support/FileOutputBuffer.cpp
Index: llvm/trunk/lib/Support/FileOutputBuffer.cpp
===================================================================
--- llvm/trunk/lib/Support/FileOutputBuffer.cpp
+++ llvm/trunk/lib/Support/FileOutputBuffer.cpp
@@ -120,7 +120,7 @@
return llvm::make_unique<InMemoryBuffer>(Path, MB, Mode);
}
-static Expected<std::unique_ptr<OnDiskBuffer>>
+static Expected<std::unique_ptr<FileOutputBuffer>>
createOnDiskBuffer(StringRef Path, size_t Size, unsigned Mode) {
Expected<fs::TempFile> FileOrErr =
fs::TempFile::create(Path + ".tmp%%%%%%%", Mode);
@@ -144,10 +144,14 @@
std::error_code EC;
auto MappedFile = llvm::make_unique<fs::mapped_file_region>(
File.FD, fs::mapped_file_region::readwrite, Size, 0, EC);
+
+ // mmap(2) can fail if the underlying filesystem does not support it.
+ // If that happens, we fall back to in-memory buffer as the last resort.
if (EC) {
consumeError(File.discard());
- return errorCodeToError(EC);
+ return createInMemoryBuffer(Path, Size, Mode);
}
+
return llvm::make_unique<OnDiskBuffer>(Path, std::move(File),
std::move(MappedFile));
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56949.182977.patch
Type: text/x-patch
Size: 1162 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190122/5145edfb/attachment.bin>
More information about the llvm-commits
mailing list