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(Path, MB, Mode); } -static Expected> +static Expected> createOnDiskBuffer(StringRef Path, size_t Size, unsigned Mode) { Expected FileOrErr = fs::TempFile::create(Path + ".tmp%%%%%%%", Mode); @@ -144,10 +144,14 @@ std::error_code EC; auto MappedFile = llvm::make_unique( 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(Path, std::move(File), std::move(MappedFile)); }