Skip to content

Commit 0895ac2

Browse files
authored
Merge pull request #1052 from flang-compiler/jpr-e78-lowering
Cherry pick non advancing IO runtime fix and add TODO for Size= specifier
2 parents 3ef51bf + 8399bd1 commit 0895ac2

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

flang/lib/Lower/IO.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#include "flang/Lower/IO.h"
1314
#include "ConvertVariable.h"
1415
#include "StatementContext.h"
1516
#include "flang/Lower/Allocatable.h"
1617
#include "flang/Lower/Bridge.h"
1718
#include "flang/Lower/ConvertExpr.h"
18-
#include "flang/Lower/IO.h"
1919
#include "flang/Lower/PFTBuilder.h"
2020
#include "flang/Lower/Runtime.h"
2121
#include "flang/Lower/Support/Utils.h"
@@ -946,6 +946,7 @@ mlir::Value genIOOption<Fortran::parser::IoControlSpec::Pos>(
946946
const Fortran::parser::IoControlSpec::Pos &spec) {
947947
return genIntIOOption<mkIOKey(SetPos)>(converter, loc, cookie, stmtCtx, spec);
948948
}
949+
949950
template <>
950951
mlir::Value genIOOption<Fortran::parser::IoControlSpec::Rec>(
951952
Fortran::lower::AbstractConverter &converter, mlir::Location loc,
@@ -954,6 +955,15 @@ mlir::Value genIOOption<Fortran::parser::IoControlSpec::Rec>(
954955
return genIntIOOption<mkIOKey(SetRec)>(converter, loc, cookie, stmtCtx, spec);
955956
}
956957

958+
template <>
959+
mlir::Value genIOOption<Fortran::parser::IoControlSpec::Size>(
960+
Fortran::lower::AbstractConverter &converter, mlir::Location loc,
961+
mlir::Value cookie, Fortran::lower::StatementContext &,
962+
const Fortran::parser::IoControlSpec::Size &) {
963+
// Runtime GetSize is not implemented yet.
964+
TODO(loc, "SIZE= specifier in a data transfer statement");
965+
}
966+
957967
//===----------------------------------------------------------------------===//
958968
// Gather IO statement condition specifier information (if any).
959969
//===----------------------------------------------------------------------===//

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)