diff --git a/flang/runtime/io-api.cpp b/flang/runtime/io-api.cpp index 39ac8c9eb6defb4..7023f61ba34de75 100644 --- a/flang/runtime/io-api.cpp +++ b/flang/runtime/io-api.cpp @@ -623,6 +623,7 @@ bool IODEF(SetRec)(Cookie cookie, std::int64_t rec) { handler.SignalError( IostatBadOpOnChildUnit, "REC= specifier on child I/O"); } else { + handler.HasRec(); unit->SetDirectRec(rec, handler); } } else if (!io.get_if()) { diff --git a/flang/runtime/io-error.cpp b/flang/runtime/io-error.cpp index 7a90966f81047f3..37909e8e6dad2cb 100644 --- a/flang/runtime/io-error.cpp +++ b/flang/runtime/io-error.cpp @@ -25,7 +25,9 @@ void IoErrorHandler::SignalError(int iostatOrErrno, const char *msg, ...) { case IostatOk: return; case IostatEnd: - if (flags_ & (hasIoStat | hasEnd)) { + if ((flags_ & (hasIoStat | hasEnd)) || + ((flags_ & hasErr) && (flags_ & hasRec))) { + // EOF goes to ERR= when REC= is present if (ioStat_ == IostatOk || ioStat_ < IostatEnd) { ioStat_ = IostatEnd; } diff --git a/flang/runtime/io-error.h b/flang/runtime/io-error.h index 426573e2faf00cf..39a343c8e0a516c 100644 --- a/flang/runtime/io-error.h +++ b/flang/runtime/io-error.h @@ -33,6 +33,7 @@ class IoErrorHandler : public Terminator { RT_API_ATTRS void HasEndLabel() { flags_ |= hasEnd; } RT_API_ATTRS void HasEorLabel() { flags_ |= hasEor; } RT_API_ATTRS void HasIoMsg() { flags_ |= hasIoMsg; } + RT_API_ATTRS void HasRec() { flags_ |= hasRec; } RT_API_ATTRS bool InError() const { return ioStat_ != IostatOk || pendingError_ != IostatOk; @@ -70,6 +71,7 @@ class IoErrorHandler : public Terminator { hasEnd = 4, // END= hasEor = 8, // EOR= hasIoMsg = 16, // IOMSG= + hasRec = 32, // REC= }; std::uint8_t flags_{0}; int ioStat_{IostatOk};