[clang] 0e8506d - [SystemZ][z/OS] Pass OpenFlags when creating tmp files

Abhina Sreeskantharajan via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 8 11:45:41 PDT 2021


Author: Abhina Sreeskantharajan
Date: 2021-06-08T14:45:34-04:00
New Revision: 0e8506debae3ad534b4eecfa922fc6281506a635

URL: https://github.com/llvm/llvm-project/commit/0e8506debae3ad534b4eecfa922fc6281506a635
DIFF: https://github.com/llvm/llvm-project/commit/0e8506debae3ad534b4eecfa922fc6281506a635.diff

LOG: [SystemZ][z/OS] Pass OpenFlags when creating tmp files

This patch https://reviews.llvm.org/D102876 caused some lit regressions on z/OS because tmp files were no longer being opened based on binary/text mode. This patch passes OpenFlags when creating tmp files so we can open files in different modes.

Reviewed By: amccarth

Differential Revision: https://reviews.llvm.org/D103806

Added: 
    

Modified: 
    clang/lib/Frontend/CompilerInstance.cpp
    llvm/include/llvm/Support/FileSystem.h
    llvm/lib/Support/Path.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index 32e7fdf64fa9..a70fe95800e1 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -828,7 +828,9 @@ CompilerInstance::createOutputFileImpl(StringRef OutputPath, bool Binary,
     TempPath += OutputExtension;
     TempPath += ".tmp";
     Expected<llvm::sys::fs::TempFile> ExpectedFile =
-        llvm::sys::fs::TempFile::create(TempPath);
+        llvm::sys::fs::TempFile::create(
+            TempPath, llvm::sys::fs::all_read | llvm::sys::fs::all_write,
+            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
index 526a97f75224..c7ab0671082d 100644
--- a/llvm/include/llvm/Support/FileSystem.h
+++ b/llvm/include/llvm/Support/FileSystem.h
@@ -857,7 +857,8 @@ class TempFile {
   /// This creates a temporary file with createUniqueFile and schedules it for
   /// deletion with sys::RemoveFileOnSignal.
   static Expected<TempFile> create(const Twine &Model,
-                                   unsigned Mode = all_read | all_write);
+                                   unsigned Mode = all_read | all_write,
+                                   OpenFlags ExtraFlags = OF_None);
   TempFile(TempFile &&Other);
   TempFile &operator=(TempFile &&Other);
 

diff  --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp
index d549b0011b1f..a724ba2faf93 100644
--- a/llvm/lib/Support/Path.cpp
+++ b/llvm/lib/Support/Path.cpp
@@ -1288,11 +1288,12 @@ Error TempFile::keep() {
   return Error::success();
 }
 
-Expected<TempFile> TempFile::create(const Twine &Model, unsigned Mode) {
+Expected<TempFile> TempFile::create(const Twine &Model, unsigned Mode,
+                                    OpenFlags ExtraFlags) {
   int FD;
   SmallString<128> ResultPath;
   if (std::error_code EC =
-          createUniqueFile(Model, FD, ResultPath, OF_Delete, Mode))
+          createUniqueFile(Model, FD, ResultPath, OF_Delete | ExtraFlags, Mode))
     return errorCodeToError(EC);
 
   TempFile Ret(ResultPath, FD);


        


More information about the cfe-commits mailing list