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

Abhina Sree via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 7 06:03:29 PDT 2021


abhina.sreeskantharajan created this revision.
Herald added subscribers: dexonsmith, hiraditya.
abhina.sreeskantharajan requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103806

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


Index: llvm/lib/Support/Path.cpp
===================================================================
--- llvm/lib/Support/Path.cpp
+++ llvm/lib/Support/Path.cpp
@@ -1288,11 +1288,11 @@
   return Error::success();
 }
 
-Expected<TempFile> TempFile::create(const Twine &Model, unsigned Mode) {
+Expected<TempFile> 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);
Index: llvm/include/llvm/Support/FileSystem.h
===================================================================
--- llvm/include/llvm/Support/FileSystem.h
+++ 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<TempFile> 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);
 
Index: clang/lib/Frontend/CompilerInstance.cpp
===================================================================
--- clang/lib/Frontend/CompilerInstance.cpp
+++ clang/lib/Frontend/CompilerInstance.cpp
@@ -828,7 +828,10 @@
     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,
+            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 {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103806.350261.patch
Type: text/x-patch
Size: 2144 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210607/bc88f304/attachment.bin>


More information about the cfe-commits mailing list