Skip to content

Commit bf95854

Browse files
authored
[flang] EOF goes to ERR= in READ(..., REC=) (#122608)
A direct access READ that tries to read past the end of the file must recover the error via an ERR= label, not an END= label (which is not allowed to be present). Fixes #122150.
1 parent 9696355 commit bf95854

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

flang/runtime/io-api.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,7 @@ bool IODEF(SetRec)(Cookie cookie, std::int64_t rec) {
623623
handler.SignalError(
624624
IostatBadOpOnChildUnit, "REC= specifier on child I/O");
625625
} else {
626+
handler.HasRec();
626627
unit->SetDirectRec(rec, handler);
627628
}
628629
} else if (!io.get_if<ErroneousIoStatementState>()) {

flang/runtime/io-error.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ void IoErrorHandler::SignalError(int iostatOrErrno, const char *msg, ...) {
2525
case IostatOk:
2626
return;
2727
case IostatEnd:
28-
if (flags_ & (hasIoStat | hasEnd)) {
28+
if ((flags_ & (hasIoStat | hasEnd)) ||
29+
((flags_ & hasErr) && (flags_ & hasRec))) {
30+
// EOF goes to ERR= when REC= is present
2931
if (ioStat_ == IostatOk || ioStat_ < IostatEnd) {
3032
ioStat_ = IostatEnd;
3133
}

flang/runtime/io-error.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class IoErrorHandler : public Terminator {
3333
RT_API_ATTRS void HasEndLabel() { flags_ |= hasEnd; }
3434
RT_API_ATTRS void HasEorLabel() { flags_ |= hasEor; }
3535
RT_API_ATTRS void HasIoMsg() { flags_ |= hasIoMsg; }
36+
RT_API_ATTRS void HasRec() { flags_ |= hasRec; }
3637

3738
RT_API_ATTRS bool InError() const {
3839
return ioStat_ != IostatOk || pendingError_ != IostatOk;
@@ -70,6 +71,7 @@ class IoErrorHandler : public Terminator {
7071
hasEnd = 4, // END=
7172
hasEor = 8, // EOR=
7273
hasIoMsg = 16, // IOMSG=
74+
hasRec = 32, // REC=
7375
};
7476
std::uint8_t flags_{0};
7577
int ioStat_{IostatOk};

0 commit comments

Comments
 (0)