Skip to content

Commit

Permalink
[flang] Fix buffering read->write transition
Browse files Browse the repository at this point in the history
The buffer needs to be Reset() after a Flush(), since the
Flush() can be a no-op after a read->write transition.
And record numbers are 1-based, not 0-based.
This fixes a bug with rewrites of records that have been
recently read.

Differential revision: https://reviews.llvm.org/D88612
  • Loading branch information
klausler committed Oct 1, 2020
1 parent 75a5ec1 commit 61687f3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion flang/runtime/buffer.h
Expand Up @@ -94,7 +94,7 @@ template <typename STORE> class FileFrame {
start_ + (at - fileOffset_) + static_cast<std::int64_t>(bytes) >
size_) {
Flush(handler);
fileOffset_ = at;
Reset(at);
Reallocate(bytes, handler);
}
dirty_ = true;
Expand Down
2 changes: 1 addition & 1 deletion flang/runtime/io-api.cpp
Expand Up @@ -518,7 +518,7 @@ bool IONAME(SetRec)(Cookie cookie, std::int64_t rec) {
}
connection.currentRecordNumber = rec;
if (auto *unit{io.GetExternalFileUnit()}) {
unit->SetPosition(rec * *connection.recordLength);
unit->SetPosition((rec - 1) * *connection.recordLength);
}
return true;
}
Expand Down

0 comments on commit 61687f3

Please sign in to comment.