[clang] [mlir] [SystemZ][CIR] Fix tests failing on z/OS (PR #246554)
Sean Perry via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 26 21:08:20 PST 2026
https://github.com/perry-ca updated https://github.com/llvm/llvm-project/pull/246554
>From 6d1dce7e1792614c9074f0f2ed890817041d7396 Mon Sep 17 00:00:00 2001
From: Sean Perry <perry at ca.ibm.com>
Date: Thu, 26 Nov 2026 16:53:47 -0500
Subject: [PATCH 1/2] opening files in text & couple other fixes
---
clang/lib/CIR/CodeGen/CIRGenRecordLayoutBuilder.cpp | 1 +
clang/test/CIR/emit-actions.cpp | 4 ++--
clang/tools/cir-offload-merge/cir-offload-merge.cpp | 2 +-
mlir/include/mlir/Support/FileUtilities.h | 4 +++-
mlir/lib/Parser/Parser.cpp | 3 ++-
mlir/lib/Support/FileUtilities.cpp | 10 ++++++----
mlir/lib/Tools/mlir-opt/MlirOptMain.cpp | 3 ++-
7 files changed, 17 insertions(+), 10 deletions(-)
diff --git a/clang/lib/CIR/CodeGen/CIRGenRecordLayoutBuilder.cpp b/clang/lib/CIR/CodeGen/CIRGenRecordLayoutBuilder.cpp
index 6b9b231e17be3d..0416959ce08b6b 100644
--- a/clang/lib/CIR/CodeGen/CIRGenRecordLayoutBuilder.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenRecordLayoutBuilder.cpp
@@ -994,6 +994,7 @@ CIRGenTypes::computeRecordLayout(const RecordDecl *rd, cir::RecordType *ty) {
rd->dump(llvm::outs());
llvm::outs() << "\nLayout: ";
rl->print(llvm::outs());
+ llvm::outs().flush();
}
// TODO: implement verification
diff --git a/clang/test/CIR/emit-actions.cpp b/clang/test/CIR/emit-actions.cpp
index 2e9e4d961dfabc..dd324668052111 100644
--- a/clang/test/CIR/emit-actions.cpp
+++ b/clang/test/CIR/emit-actions.cpp
@@ -7,7 +7,7 @@
// RUN: llvm-objdump -t %t.o | FileCheck %s -check-prefix=OBJ
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir-bc %s -o %t.cirbc
-// RUN: od -An -c -N4 %t.cirbc | FileCheck %s --check-prefix=CIRBC-MAGIC
+// RUN: od -An -tx1 -N4 %t.cirbc | FileCheck %s --ignore-case --check-prefix=CIRBC-MAGIC
// RUN: not grep -q "cir.global" %t.cirbc
// RUN: cir-opt %t.cirbc | FileCheck %s -check-prefix=CIRBC
@@ -31,6 +31,6 @@ int x = 1;
// OBJ: .data
// OBJ-SAME: x
-// CIRBC-MAGIC: M L 357 R
+// CIRBC-MAGIC: 4d 4c ef 52
// CIRBC: cir.global {{.*}}@x = #cir.int<1> : !s32i
diff --git a/clang/tools/cir-offload-merge/cir-offload-merge.cpp b/clang/tools/cir-offload-merge/cir-offload-merge.cpp
index cde2cd28345fe9..ac437bc0357eac 100644
--- a/clang/tools/cir-offload-merge/cir-offload-merge.cpp
+++ b/clang/tools/cir-offload-merge/cir-offload-merge.cpp
@@ -151,7 +151,7 @@ static int writeModuleToOutput(mlir::ModuleOp moduleOp,
assert(!moduleOp->getParentOp() && "expected a top-level module");
std::string errorMessage;
std::unique_ptr<llvm::ToolOutputFile> outputFile =
- mlir::openOutputFile(outputFileName, &errorMessage);
+ mlir::openOutputFile(outputFileName, &errorMessage, /*IsText=*/true);
if (!outputFile) {
mlir::emitError(moduleOp.getLoc(), errorMessage);
return 1;
diff --git a/mlir/include/mlir/Support/FileUtilities.h b/mlir/include/mlir/Support/FileUtilities.h
index fca17d82a2bf2b..4d572dabb1a0f0 100644
--- a/mlir/include/mlir/Support/FileUtilities.h
+++ b/mlir/include/mlir/Support/FileUtilities.h
@@ -39,9 +39,11 @@ openInputFile(llvm::StringRef inputFilename, llvm::Align alignment,
/// Open the file specified by its name for writing. Write the error message to
/// `errorMessage` if errors occur and `errorMessage` is not nullptr.
+/// `isText` is true the file is opened in text mode; the default is
+/// binary.
std::unique_ptr<llvm::ToolOutputFile>
openOutputFile(llvm::StringRef outputFilename,
- std::string *errorMessage = nullptr);
+ std::string *errorMessage = nullptr, bool isText = false);
} // namespace mlir
diff --git a/mlir/lib/Parser/Parser.cpp b/mlir/lib/Parser/Parser.cpp
index 310680bcfb34f4..f20502f3242144 100644
--- a/mlir/lib/Parser/Parser.cpp
+++ b/mlir/lib/Parser/Parser.cpp
@@ -79,7 +79,8 @@ static LogicalResult loadSourceFileBuffer(llvm::StringRef filename,
return emitError(mlir::UnknownLoc::get(ctx),
"only main buffer parsed at the moment");
}
- auto fileOrErr = llvm::MemoryBuffer::getFileOrSTDIN(filename);
+ auto fileOrErr =
+ llvm::MemoryBuffer::getFileOrSTDIN(filename, /*IsText=*/true);
if (fileOrErr.getError())
return emitError(mlir::UnknownLoc::get(ctx),
"could not open input file " + filename);
diff --git a/mlir/lib/Support/FileUtilities.cpp b/mlir/lib/Support/FileUtilities.cpp
index a5c44d3a9c8eb0..c18dc7013637c9 100644
--- a/mlir/lib/Support/FileUtilities.cpp
+++ b/mlir/lib/Support/FileUtilities.cpp
@@ -23,7 +23,7 @@ static std::unique_ptr<llvm::MemoryBuffer>
openInputFileImpl(StringRef inputFilename, std::string *errorMessage,
std::optional<llvm::Align> alignment) {
auto fileOrErr = llvm::MemoryBuffer::getFileOrSTDIN(
- inputFilename, /*IsText=*/false, /*RequiresNullTerminator=*/true,
+ inputFilename, /*IsText=*/true, /*RequiresNullTerminator=*/true,
alignment);
if (std::error_code error = fileOrErr.getError()) {
if (errorMessage)
@@ -46,10 +46,12 @@ mlir::openInputFile(llvm::StringRef inputFilename, llvm::Align alignment,
}
std::unique_ptr<llvm::ToolOutputFile>
-mlir::openOutputFile(StringRef outputFilename, std::string *errorMessage) {
+mlir::openOutputFile(StringRef outputFilename, std::string *errorMessage,
+ bool IsText) {
std::error_code error;
- auto result = std::make_unique<llvm::ToolOutputFile>(outputFilename, error,
- llvm::sys::fs::OF_None);
+ auto result = std::make_unique<llvm::ToolOutputFile>(
+ outputFilename, error,
+ IsText ? llvm::sys::fs::OF_Text : llvm::sys::fs::OF_None);
if (error) {
if (errorMessage)
*errorMessage = "cannot open output file '" + outputFilename.str() +
diff --git a/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp b/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
index 0a564a5055cfdf..bbdcf9deb18636 100644
--- a/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
+++ b/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
@@ -869,7 +869,8 @@ LogicalResult mlir::MlirOptMain(int argc, char **argv,
return failure();
}
- auto output = openOutputFile(outputFilename, &errorMessage);
+ auto output = openOutputFile(outputFilename, &errorMessage,
+ /*isText=*/!config.shouldEmitBytecode());
if (!output) {
llvm::errs() << errorMessage << "\n";
return failure();
>From 14e047b28096ecec4b5e5923e732c370220e105a Mon Sep 17 00:00:00 2001
From: Sean Perry <perry at ca.ibm.com>
Date: Fri, 27 Nov 2026 00:07:57 -0500
Subject: [PATCH 2/2] remove blank line
---
mlir/include/mlir/Support/FileUtilities.h | 1 -
1 file changed, 1 deletion(-)
diff --git a/mlir/include/mlir/Support/FileUtilities.h b/mlir/include/mlir/Support/FileUtilities.h
index 4d572dabb1a0f0..255d57a1c2111f 100644
--- a/mlir/include/mlir/Support/FileUtilities.h
+++ b/mlir/include/mlir/Support/FileUtilities.h
@@ -44,7 +44,6 @@ openInputFile(llvm::StringRef inputFilename, llvm::Align alignment,
std::unique_ptr<llvm::ToolOutputFile>
openOutputFile(llvm::StringRef outputFilename,
std::string *errorMessage = nullptr, bool isText = false);
-
} // namespace mlir
#endif // MLIR_SUPPORT_FILEUTILITIES_H_
More information about the cfe-commits
mailing list