diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -828,7 +828,10 @@ TempPath += OutputExtension; TempPath += ".tmp"; Expected ExpectedFile = - llvm::sys::fs::TempFile::create(TempPath); + llvm::sys::fs::TempFile::create( + TempPath, llvm::sys::fs::all_read | llvm::sys::fs::all_write, + llvm::sys::fs::OF_Delete | + (Binary ? llvm::sys::fs::OF_None : llvm::sys::fs::OF_Text)); llvm::Error E = handleErrors( ExpectedFile.takeError(), [&](const llvm::ECError &E) -> llvm::Error { diff --git a/llvm/include/llvm/Support/FileSystem.h b/llvm/include/llvm/Support/FileSystem.h --- a/llvm/include/llvm/Support/FileSystem.h +++ b/llvm/include/llvm/Support/FileSystem.h @@ -857,7 +857,8 @@ /// This creates a temporary file with createUniqueFile and schedules it for /// deletion with sys::RemoveFileOnSignal. static Expected create(const Twine &Model, - unsigned Mode = all_read | all_write); + unsigned Mode = all_read | all_write, + OpenFlags Flags = OF_Delete); TempFile(TempFile &&Other); TempFile &operator=(TempFile &&Other); diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp --- a/llvm/lib/Support/Path.cpp +++ b/llvm/lib/Support/Path.cpp @@ -1288,11 +1288,11 @@ return Error::success(); } -Expected TempFile::create(const Twine &Model, unsigned Mode) { +Expected TempFile::create(const Twine &Model, unsigned Mode, + OpenFlags Flags) { int FD; SmallString<128> ResultPath; - if (std::error_code EC = - createUniqueFile(Model, FD, ResultPath, OF_Delete, Mode)) + if (std::error_code EC = createUniqueFile(Model, FD, ResultPath, Flags, Mode)) return errorCodeToError(EC); TempFile Ret(ResultPath, FD);