[flang-commits] [PATCH] D151134: [flang][runtime] Complete partial output records when positioning/closing after non-advancing output

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Mon May 22 12:00:02 PDT 2023


klausler created this revision.
klausler added a reviewer: vdonaldson.
klausler added a project: Flang.
Herald added subscribers: sunshaoce, jdoerfert.
Herald added a project: All.
klausler requested review of this revision.

Before positioning or closing a unit after a non-advancing output statement
has left a partial record in its buffer, complete the record by calling   
AdvanceRecord().  Fixes https://github.com/llvm/llvm-project/issues/59761.


https://reviews.llvm.org/D151134

Files:
  flang/runtime/unit.cpp


Index: flang/runtime/unit.cpp
===================================================================
--- flang/runtime/unit.cpp
+++ flang/runtime/unit.cpp
@@ -893,6 +893,12 @@
 }
 
 void ExternalFileUnit::DoImpliedEndfile(IoErrorHandler &handler) {
+  if (!impliedEndfile_ && direction_ == Direction::Output && IsRecordFile() &&
+      access != Access::Direct && leftTabLimit) {
+    // Complete partial record after non-advancing write before
+    // positioning or closing the unit.  Usually sets impliedEndfile_.
+    AdvanceRecord(handler);
+  }
   if (impliedEndfile_) {
     impliedEndfile_ = false;
     if (access != Access::Direct && IsRecordFile() && mayPosition()) {
@@ -905,7 +911,7 @@
   if (IsRecordFile() && access != Access::Direct) {
     furthestPositionInRecord =
         std::max(positionInRecord, furthestPositionInRecord);
-    if (furthestPositionInRecord > 0) {
+    if (leftTabLimit) {
       // Last read/write was non-advancing, so AdvanceRecord() was not called.
       leftTabLimit.reset();
       ++currentRecordNumber;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151134.524418.patch
Type: text/x-patch
Size: 1049 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230522/1c30acf5/attachment-0001.bin>


More information about the flang-commits mailing list