[flang][runtime] Preserve effect of positioning in record in non-advancing output

When formatted non-advancing output ends in a control edit descriptor
like nX or Tn or TRn that effectively extends the record, fill any
gap with explicit blanks at the completion of the WRITE.

Differential Revision: https://reviews.llvm.org/D123716
This commit is contained in:
Peter Klausler 2022-04-04 14:30:38 -07:00
parent 724709e09d
commit a68612a964
1 changed files with 6 additions and 1 deletions

View File

@ -318,8 +318,13 @@ void ExternalIoStatementState<DIR>::CompleteOperation() {
if (!mutableModes().nonAdvancing || GetIoStat() == IostatEor) {
FinishReadingRecord();
}
} else {
} else { // output
if (mutableModes().nonAdvancing) {
// Make effects of positioning past the last Emit() visible with blanks.
std::int64_t n{unit().positionInRecord - unit().furthestPositionInRecord};
unit().positionInRecord = unit().furthestPositionInRecord;
while (n-- > 0 && unit().Emit(" ", 1, 1, *this)) {
}
unit().leftTabLimit = unit().furthestPositionInRecord;
} else {
unit().leftTabLimit.reset();