[flang-commits] [PATCH] D129019: [flang][runtime] Make ENDFILE work after non-advancing READ
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Fri Jul 1 15:09:27 PDT 2022
klausler created this revision.
klausler added a reviewer: vdonaldson.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
klausler requested review of this revision.
An ENDFILE statement executed when a non-advancing READ has
left the unit in the middle of a record must truncate the file
at that position.
https://reviews.llvm.org/D129019
Files:
flang/runtime/unit.cpp
Index: flang/runtime/unit.cpp
===================================================================
--- flang/runtime/unit.cpp
+++ flang/runtime/unit.cpp
@@ -887,16 +887,20 @@
void ExternalFileUnit::DoEndfile(IoErrorHandler &handler) {
if (IsRecordFile() && access != Access::Direct) {
+ furthestPositionInRecord =
+ std::max(positionInRecord, furthestPositionInRecord);
if (furthestPositionInRecord > 0) {
- // Last write was non-advancing, so AdvanceRecord() was not called.
+ // Last read/write was non-advancing, so AdvanceRecord() was not called.
leftTabLimit.reset();
++currentRecordNumber;
}
endfileRecordNumber = currentRecordNumber;
}
- FlushOutput(handler);
- Truncate(frameOffsetInFile_ + recordOffsetInFrame_ + furthestPositionInRecord,
- handler);
+ frameOffsetInFile_ += recordOffsetInFrame_ + furthestPositionInRecord;
+ recordOffsetInFrame_ = 0;
+ // Flush (if dirty) and reset the frame (even if reading)
+ WriteFrame(frameOffsetInFile_, 0, handler);
+ Truncate(frameOffsetInFile_, handler);
BeginRecord();
impliedEndfile_ = false;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129019.441794.patch
Type: text/x-patch
Size: 1126 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220701/2a081309/attachment.bin>
More information about the flang-commits
mailing list