diff options
Diffstat (limited to 'llvm/lib/Support/FileOutputBuffer.cpp')
-rw-r--r-- | llvm/lib/Support/FileOutputBuffer.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/llvm/lib/Support/FileOutputBuffer.cpp b/llvm/lib/Support/FileOutputBuffer.cpp index cf21cc19c01..b0b817b4bdd 100644 --- a/llvm/lib/Support/FileOutputBuffer.cpp +++ b/llvm/lib/Support/FileOutputBuffer.cpp @@ -120,7 +120,7 @@ createInMemoryBuffer(StringRef Path, size_t Size, unsigned Mode) { 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 @@ createOnDiskBuffer(StringRef Path, size_t Size, unsigned Mode) { 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)); } |