Skip to content

Commit ba2c421

Browse files
author
Tony Tao
committed
add test for output encoding and consolidate code
1 parent 50a7686 commit ba2c421

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Checks encoding of output file
2+
// This is only required for z/OS.
3+
//
4+
// REQUIRES: system-zos, systemz-registered-target
5+
// RUN: %clang_cc1 -triple s390x-ibm-zos -S %s -o %t.s
6+
// RUN: ls -T %t.s | FileCheck %s
7+
8+
// CHECK: t IBM-1047 T=on
9+
void foo() { return; }

llvm/lib/Support/VirtualOutputBackends.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,18 @@ static Error createDirectoriesOnDemand(StringRef OutputPath,
254254
});
255255
}
256256

257+
static sys::fs::OpenFlags generateFlagsFromConfig(OutputConfig Config) {
258+
sys::fs::OpenFlags OF = sys::fs::OF_None;
259+
if (Config.getTextWithCRLF())
260+
OF |= sys::fs::OF_TextWithCRLF;
261+
else if (Config.getText())
262+
OF |= sys::fs::OF_Text;
263+
if (Config.getAppend())
264+
OF |= sys::fs::OF_Append;
265+
266+
return OF;
267+
}
268+
257269
Error OnDiskOutputFile::tryToCreateTemporary(std::optional<int> &FD) {
258270
// Create a temporary file.
259271
// Insert -%%%%%%%% before the extension (if any), and because some tools
@@ -269,13 +281,7 @@ Error OnDiskOutputFile::tryToCreateTemporary(std::optional<int> &FD) {
269281
return createDirectoriesOnDemand(OutputPath, Config, [&]() -> Error {
270282
int NewFD;
271283
SmallString<128> UniquePath;
272-
sys::fs::OpenFlags OF = sys::fs::OF_None;
273-
if (Config.getTextWithCRLF())
274-
OF |= sys::fs::OF_TextWithCRLF;
275-
else if (Config.getText())
276-
OF |= sys::fs::OF_Text;
277-
if (Config.getAppend())
278-
OF |= sys::fs::OF_Append;
284+
sys::fs::OpenFlags OF = generateFlagsFromConfig(Config);
279285
if (std::error_code EC =
280286
sys::fs::createUniqueFile(ModelPath, NewFD, UniquePath, OF))
281287
return make_error<TempFileOutputError>(ModelPath, OutputPath, EC);
@@ -319,13 +325,7 @@ Error OnDiskOutputFile::initializeFile(std::optional<int> &FD) {
319325
// Not using a temporary file. Open the final output file.
320326
return createDirectoriesOnDemand(OutputPath, Config, [&]() -> Error {
321327
int NewFD;
322-
sys::fs::OpenFlags OF = sys::fs::OF_None;
323-
if (Config.getTextWithCRLF())
324-
OF |= sys::fs::OF_TextWithCRLF;
325-
else if (Config.getText())
326-
OF |= sys::fs::OF_Text;
327-
if (Config.getAppend())
328-
OF |= sys::fs::OF_Append;
328+
sys::fs::OpenFlags OF = generateFlagsFromConfig(Config);
329329
if (std::error_code EC = sys::fs::openFileForWrite(
330330
OutputPath, NewFD, sys::fs::CD_CreateAlways, OF))
331331
return convertToOutputError(OutputPath, EC);

0 commit comments

Comments
 (0)