[llvm] [flang] Blank-fill internal list-directed record when no output is emitted (PR #213205)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 30 23:46:57 PDT 2026
https://github.com/ejose02 updated https://github.com/llvm/llvm-project/pull/213205
>From 5436767daf1e5e7b722045adfe4a278378b1347e Mon Sep 17 00:00:00 2001
From: ejose <ejose at amd.com>
Date: Fri, 31 Jul 2026 05:15:53 +0000
Subject: [PATCH] [flang] Blank-fill internal list-directed record when no
output is emitted
Fixes #205989
Root cause: CompleteOperation() only called AdvanceRecord() when furthestPositionInRecord > 0, so zero-byte writes skipped blank-fill.
Fix: always call AdvanceRecord() for internal list-directed output. Added test for validation.
---
flang-rt/lib/runtime/io-stmt.cpp | 4 +---
flang-rt/unittests/Runtime/NumericalFormatTest.cpp | 14 ++++++++++++++
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/flang-rt/lib/runtime/io-stmt.cpp b/flang-rt/lib/runtime/io-stmt.cpp
index 08931fc781428..56996380ffa66 100644
--- a/flang-rt/lib/runtime/io-stmt.cpp
+++ b/flang-rt/lib/runtime/io-stmt.cpp
@@ -219,9 +219,7 @@ template <Direction DIR>
void InternalListIoStatementState<DIR>::CompleteOperation() {
if (!this->completedOperation()) {
if constexpr (DIR == Direction::Output) {
- if (unit_.furthestPositionInRecord > 0) {
- unit_.AdvanceRecord(*this);
- }
+ unit_.AdvanceRecord(*this);
}
IoStatementBase::CompleteOperation();
}
diff --git a/flang-rt/unittests/Runtime/NumericalFormatTest.cpp b/flang-rt/unittests/Runtime/NumericalFormatTest.cpp
index 6af17e99418b4..f96e5cd294de8 100644
--- a/flang-rt/unittests/Runtime/NumericalFormatTest.cpp
+++ b/flang-rt/unittests/Runtime/NumericalFormatTest.cpp
@@ -244,6 +244,20 @@ TEST(IOApiTests, ListInputComplexRegressionTest) {
<< "', but got '" << output << "'";
}
+TEST(IOApiTests, InternalListBlankFillNoOutputTest) {
+ static constexpr int bufferSize{10};
+ char buffer[bufferSize];
+ std::memcpy(buffer, "abcdefghij", bufferSize);
+ auto cookie{IONAME(BeginInternalListOutput)(buffer, bufferSize)};
+ auto status{IONAME(EndIoStatement)(cookie)};
+ ASSERT_EQ(status, 0) << "EndIoStatement failed, status "
+ << static_cast<int>(status);
+ EXPECT_TRUE(
+ CompareFormattedStrings(" ", std::string{buffer, bufferSize}))
+ << "Expected all blanks but got '" << std::string{buffer, bufferSize}
+ << "'";
+}
+
TEST(IOApiTests, DescriptorOutputTest) {
static constexpr int bufferSize{10};
char buffer[bufferSize];
More information about the llvm-commits
mailing list