[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
Wed Jul 6 17:30:52 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG0508fd5935d9: [flang][runtime] Make ENDFILE work after non-advancing READ (authored by klausler).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129019/new/

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.442732.patch
Type: text/x-patch
Size: 1126 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220707/fc12d06f/attachment.bin>


More information about the flang-commits mailing list