Index: flang/runtime/unit.h =================================================================== --- flang/runtime/unit.h +++ flang/runtime/unit.h @@ -115,6 +115,7 @@ void DoEndfile(IoErrorHandler &); void CommitWrites(); bool CheckDirectAccess(IoErrorHandler &); + void HitEndOnRead(IoErrorHandler &); int unitNumber_{-1}; Direction direction_{Direction::Output}; Index: flang/runtime/unit.cpp =================================================================== --- flang/runtime/unit.cpp +++ flang/runtime/unit.cpp @@ -348,10 +348,7 @@ furthestPositionInRecord = furthestAfter; return true; } else { - handler.SignalEnd(); - if (IsRecordFile() && access != Access::Direct) { - endfileRecordNumber = currentRecordNumber; - } + HitEndOnRead(handler); return false; } } @@ -384,10 +381,7 @@ if (got >= need) { return Frame() + at; } - handler.SignalEnd(); - if (IsRecordFile() && access != Access::Direct) { - endfileRecordNumber = currentRecordNumber; - } + HitEndOnRead(handler); } return nullptr; } @@ -422,7 +416,7 @@ recordLength = openRecl; } else { recordLength.reset(); - handler.SignalEnd(); + HitEndOnRead(handler); } } else { recordLength.reset(); @@ -667,7 +661,7 @@ const char *error{nullptr}; if (got < need) { if (got == recordOffsetInFrame_) { - handler.SignalEnd(); + HitEndOnRead(handler); } else { error = "Unformatted variable-length sequential file input failed at " "record #%jd (file offset %jd): truncated record header"; @@ -722,7 +716,7 @@ recordLength = length; unterminatedRecord = true; } else { - handler.SignalEnd(); + HitEndOnRead(handler); } break; } @@ -878,6 +872,13 @@ return true; } +void ExternalFileUnit::HitEndOnRead(IoErrorHandler &handler) { + handler.SignalEnd(); + if (IsRecordFile() && access != Access::Direct) { + endfileRecordNumber = currentRecordNumber; + } +} + ChildIo &ExternalFileUnit::PushChildIo(IoStatementState &parent) { OwningPtr current{std::move(child_)}; Terminator &terminator{parent.GetIoErrorHandler()};