Skip to content

Conversation

@tltao
Copy link
Contributor

@tltao tltao commented Nov 13, 2025

Non-binary output files from the compiler need the OF_Text flag set for encoding conversion to be performed correctly on z/OS.

I'm not sure if there's a portable way to test this, but if anyone has an idea I can add it.

@llvmbot
Copy link
Member

llvmbot commented Nov 13, 2025

@llvm/pr-subscribers-clang
@llvm/pr-subscribers-backend-systemz

@llvm/pr-subscribers-llvm-support

Author: Tony Tao (tltao)

Changes

Non-binary output files from the compiler need the OF_Text flag set for encoding conversion to be performed correctly on z/OS.

I'm not sure if there's a portable way to test this, but if anyone has an idea I can add it.


Full diff: https://github.com/llvm/llvm-project/pull/167939.diff

1 Files Affected:

  • (modified) llvm/lib/Support/VirtualOutputBackends.cpp (+8-1)
diff --git a/llvm/lib/Support/VirtualOutputBackends.cpp b/llvm/lib/Support/VirtualOutputBackends.cpp
index de59b8ab63a53..f44cfd419f8c7 100644
--- a/llvm/lib/Support/VirtualOutputBackends.cpp
+++ b/llvm/lib/Support/VirtualOutputBackends.cpp
@@ -269,8 +269,15 @@ Error OnDiskOutputFile::tryToCreateTemporary(std::optional<int> &FD) {
   return createDirectoriesOnDemand(OutputPath, Config, [&]() -> Error {
     int NewFD;
     SmallString<128> UniquePath;
+    sys::fs::OpenFlags OF = sys::fs::OF_None;
+    if (Config.getTextWithCRLF())
+      OF |= sys::fs::OF_TextWithCRLF;
+    else if (Config.getText())
+      OF |= sys::fs::OF_Text;
+    if (Config.getAppend())
+      OF |= sys::fs::OF_Append;
     if (std::error_code EC =
-            sys::fs::createUniqueFile(ModelPath, NewFD, UniquePath))
+            sys::fs::createUniqueFile(ModelPath, NewFD, UniquePath, OF))
       return make_error<TempFileOutputError>(ModelPath, OutputPath, EC);
 
     if (Config.getDiscardOnSignal())

@tltao tltao added the z/OS label Nov 13, 2025
@tltao tltao self-assigned this Nov 13, 2025
Copy link
Contributor

@abhina-sree abhina-sree left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@cachemeifyoucan cachemeifyoucan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer writing a unit test and it doesn't need to be a portable test (it just needs to run on the platforms that hit this error).

@llvmbot llvmbot added clang Clang issues not falling into any other category backend:SystemZ labels Nov 13, 2025
@github-actions
Copy link

github-actions bot commented Nov 13, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Collaborator

@cachemeifyoucan cachemeifyoucan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks.

@tltao
Copy link
Contributor Author

tltao commented Nov 14, 2025

@cachemeifyoucan There was a test failure on Windows in TEST(OnDiskBackendTest, Append) due to the assert assert((!(Disp == CD_CreateNew) || !(Flags & OF_Append)) in Path.inc. I fixed it by checking for getAtomicWrite() and not passing the OF_Append flag if true since to me, it doesn't make much sense to append to a temporary file. Does that sound reasonable or is there a better fix?

@cachemeifyoucan
Copy link
Collaborator

@cachemeifyoucan There was a test failure on Windows in TEST(OnDiskBackendTest, Append) due to the assert assert((!(Disp == CD_CreateNew) || !(Flags & OF_Append)) in Path.inc. I fixed it by checking for getAtomicWrite() and not passing the OF_Append flag if true since to me, it doesn't make much sense to append to a temporary file. Does that sound reasonable or is there a better fix?

Sounds reasonable. Atomic append is not OF_Append since writing to temporary. Add a comment on this will be a plus.

@tltao tltao enabled auto-merge (squash) November 14, 2025 17:38
@tltao tltao merged commit 52f2a94 into llvm:main Nov 14, 2025
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend:SystemZ clang Clang issues not falling into any other category llvm:support z/OS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants