Skip to content

Commit 424c2e0

Browse files
committed
[flang] Signal EOR in non advancing IO and move to next record
When an end of record is met in non advancing IO: - Set IOSTAT if present according to 12.11.4 (5). - Position the file to the next record (12.11.4 (4)). The previous code was only signaling EOR for fixed record length IO. Reading at 12.11.4, I do not find the rational for this condition, so I removed it. It also does not seem the presence of padding should prevent the EOR signaling. The positionning to the next record was block when EOR is signaling in FinishReadingRecord because ErrorHandler.isError() is true in this case. EOR in input is not an error, but I am not confident to modify ErrorHandler.isError() to cover that. However, In FinishReadingRecord, the code should not bail if the error is simply an end of record. I did not check the SIZE requirements here because GetSize runtime is not yet implemented. Differential Revision: https://reviews.llvm.org/D109505
1 parent df66885 commit 424c2e0

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

flang/runtime/io-stmt.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ ExternalIoStatementState<DIR>::ExternalIoStatementState(
272272
template <Direction DIR> int ExternalIoStatementState<DIR>::EndIoStatement() {
273273
if constexpr (DIR == Direction::Input) {
274274
BeginReadingRecord(); // in case there were no I/O items
275-
if (!mutableModes().nonAdvancing) {
275+
if (!mutableModes().nonAdvancing || GetIoStat() == IostatEor) {
276276
FinishReadingRecord();
277277
}
278278
} else {
@@ -559,19 +559,18 @@ std::optional<char32_t> IoStatementState::NextInField(
559559
return next;
560560
}
561561
const ConnectionState &connection{GetConnectionState()};
562-
if (!connection.IsAtEOF() && connection.isFixedRecordLength &&
563-
connection.recordLength &&
562+
if (!connection.IsAtEOF() && connection.recordLength &&
564563
connection.positionInRecord >= *connection.recordLength) {
565-
if (connection.modes.pad) { // PAD='YES'
566-
--*remaining;
567-
return std::optional<char32_t>{' '};
568-
}
569564
IoErrorHandler &handler{GetIoErrorHandler()};
570565
if (mutableModes().nonAdvancing) {
571566
handler.SignalEor();
572-
} else {
567+
} else if (connection.isFixedRecordLength && !connection.modes.pad) {
573568
handler.SignalError(IostatRecordReadOverrun);
574569
}
570+
if (connection.modes.pad) { // PAD='YES'
571+
--*remaining;
572+
return std::optional<char32_t>{' '};
573+
}
575574
}
576575
}
577576
return std::nullopt;

flang/runtime/unit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ bool ExternalFileUnit::BeginReadingRecord(IoErrorHandler &handler) {
402402
void ExternalFileUnit::FinishReadingRecord(IoErrorHandler &handler) {
403403
RUNTIME_CHECK(handler, direction_ == Direction::Input && beganReadingRecord_);
404404
beganReadingRecord_ = false;
405-
if (handler.InError()) {
405+
if (handler.InError() && handler.GetIoStat() != IostatEor) {
406406
// avoid bogus crashes in END/ERR circumstances
407407
} else if (access == Access::Sequential) {
408408
RUNTIME_CHECK(handler, recordLength.has_value());

0 commit comments

Comments
 (0)