Skip to content

[flang] Fix variable unformatted I/O bug with output after input #92828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion flang/runtime/external-unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@ Iostat ExternalFileUnit::SetDirection(Direction direction) {
}
} else {
if (mayWrite()) {
if (direction_ == Direction::Input) {
// Don't retain any input data from previous record, like a
// variable-length unformatted record footer, in the frame,
// since we're going start writing frames.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// since we're going start writing frames.
// since we're going to start writing frames.

frameOffsetInFile_ += recordOffsetInFrame_;
recordOffsetInFrame_ = 0;
}
direction_ = Direction::Output;
return IostatOk;
} else {
Expand Down Expand Up @@ -332,5 +339,4 @@ bool ExternalFileUnit::Wait(int id) {
}

} // namespace Fortran::runtime::io

#endif // !defined(RT_USE_PSEUDO_FILE_UNIT)
1 change: 1 addition & 0 deletions flang/runtime/unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ void ExternalFileUnit::FinishReadingRecord(IoErrorHandler &handler) {
furthestPositionInRecord =
std::max(furthestPositionInRecord, positionInRecord);
frameOffsetInFile_ += recordOffsetInFrame_ + furthestPositionInRecord;
recordOffsetInFrame_ = 0;
}
BeginRecord();
}
Expand Down
Loading