Skip to content

Commit

Permalink
[flang][runtime] Complete partial output records when positioning/clo…
Browse files Browse the repository at this point in the history
…sing after non-advancing output

Before positioning or closing a unit after a non-advancing output statement
has left a partial record in its buffer, complete the record by calling
AdvanceRecord().  Fixes #59761.

Differential Revision: https://reviews.llvm.org/D151134
  • Loading branch information
klausler committed May 23, 2023
1 parent b2e6b73 commit 472913c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion flang/runtime/unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,12 @@ void ExternalFileUnit::BackspaceVariableFormattedRecord(
}

void ExternalFileUnit::DoImpliedEndfile(IoErrorHandler &handler) {
if (!impliedEndfile_ && direction_ == Direction::Output && IsRecordFile() &&
access != Access::Direct && leftTabLimit) {
// Complete partial record after non-advancing write before
// positioning or closing the unit. Usually sets impliedEndfile_.
AdvanceRecord(handler);
}
if (impliedEndfile_) {
impliedEndfile_ = false;
if (access != Access::Direct && IsRecordFile() && mayPosition()) {
Expand All @@ -905,7 +911,7 @@ void ExternalFileUnit::DoEndfile(IoErrorHandler &handler) {
if (IsRecordFile() && access != Access::Direct) {
furthestPositionInRecord =
std::max(positionInRecord, furthestPositionInRecord);
if (furthestPositionInRecord > 0) {
if (leftTabLimit) {
// Last read/write was non-advancing, so AdvanceRecord() was not called.
leftTabLimit.reset();
++currentRecordNumber;
Expand Down

0 comments on commit 472913c

Please sign in to comment.