[flang-commits] [flang] bf95854 - [flang] EOF goes to ERR= in READ(..., REC=) (#122608)
via flang-commits
flang-commits at lists.llvm.org
Tue Jan 14 12:58:19 PST 2025
Author: Peter Klausler
Date: 2025-01-14T12:58:16-08:00
New Revision: bf95854e9ab1209901603d8f9edba4328eed6689
URL: https://github.com/llvm/llvm-project/commit/bf95854e9ab1209901603d8f9edba4328eed6689
DIFF: https://github.com/llvm/llvm-project/commit/bf95854e9ab1209901603d8f9edba4328eed6689.diff
LOG: [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 https://github.com/llvm/llvm-project/issues/122150.
Added:
Modified:
flang/runtime/io-api.cpp
flang/runtime/io-error.cpp
flang/runtime/io-error.h
Removed:
################################################################################
diff --git a/flang/runtime/io-api.cpp b/flang/runtime/io-api.cpp
index 39ac8c9eb6defb..7023f61ba34de7 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<ErroneousIoStatementState>()) {
diff --git a/flang/runtime/io-error.cpp b/flang/runtime/io-error.cpp
index 7a90966f81047f..37909e8e6dad2c 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 426573e2faf00c..39a343c8e0a516 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};
More information about the flang-commits
mailing list