Index: flang/runtime/internal-unit.h =================================================================== --- flang/runtime/internal-unit.h +++ flang/runtime/internal-unit.h @@ -45,6 +45,8 @@ return descriptor().template ZeroBasedIndexedElement( currentRecordNumber - 1); } + void BlankFillOutputRecord(); + StaticDescriptor staticDescriptor_; }; Index: flang/runtime/internal-unit.cpp =================================================================== --- flang/runtime/internal-unit.cpp +++ flang/runtime/internal-unit.cpp @@ -38,15 +38,9 @@ } template void InternalDescriptorUnit::EndIoStatement() { - if constexpr (DIR == Direction::Output) { // blank fill - while (char *record{CurrentRecord()}) { - if (furthestPositionInRecord < - recordLength.value_or(furthestPositionInRecord)) { - std::fill_n(record + furthestPositionInRecord, - *recordLength - furthestPositionInRecord, ' '); - } - furthestPositionInRecord = 0; - ++currentRecordNumber; + if constexpr (DIR == Direction::Output) { + if (furthestPositionInRecord > 0) { + BlankFillOutputRecord(); } } } @@ -127,18 +121,24 @@ handler.SignalEnd(); return false; } - if constexpr (DIR == Direction::Output) { // blank fill + if constexpr (DIR == Direction::Output) { + BlankFillOutputRecord(); + } + ++currentRecordNumber; + BeginRecord(); + return true; +} + +template +void InternalDescriptorUnit::BlankFillOutputRecord() { + if constexpr (DIR == Direction::Output) { if (furthestPositionInRecord < recordLength.value_or(furthestPositionInRecord)) { char *record{CurrentRecord()}; - RUNTIME_CHECK(handler, record != nullptr); std::fill_n(record + furthestPositionInRecord, *recordLength - furthestPositionInRecord, ' '); } } - ++currentRecordNumber; - BeginRecord(); - return true; } template Index: flang/unittests/Runtime/NumericalFormatTest.cpp =================================================================== --- flang/unittests/Runtime/NumericalFormatTest.cpp +++ flang/unittests/Runtime/NumericalFormatTest.cpp @@ -118,6 +118,9 @@ auto cookie{IONAME(BeginInternalArrayFormattedOutput)( section, format, std::strlen(format))}; + // Fill last line with periods + std::memset(buffer[numLines - 1], '.', lineLength); + // Write data to buffer IONAME(OutputAscii)(cookie, "WORLD", 5); IONAME(OutputAscii)(cookie, "HELLO", 5); @@ -135,7 +138,7 @@ " " "789 abcd 666 777" " 888 999 " - " "}; + "................................"}; // Ensure formatted string matches expected output EXPECT_TRUE( CompareFormattedStrings(expect, std::string{buffer[0], sizeof buffer}))