[flang-commits] [flang] 472913c - [flang][runtime] Complete partial output records when positioning/closing after non-advancing output

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Tue May 23 15:55:12 PDT 2023


Author: Peter Klausler
Date: 2023-05-23T15:54:57-07:00
New Revision: 472913c7ef7456958760cfb2cd5c6bb86323b500

URL: https://github.com/llvm/llvm-project/commit/472913c7ef7456958760cfb2cd5c6bb86323b500
DIFF: https://github.com/llvm/llvm-project/commit/472913c7ef7456958760cfb2cd5c6bb86323b500.diff

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

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.

Differential Revision: https://reviews.llvm.org/D151134

Added: 
    

Modified: 
    flang/runtime/unit.cpp

Removed: 
    


################################################################################
diff  --git a/flang/runtime/unit.cpp b/flang/runtime/unit.cpp
index af2c83509b773..5e8db046ca3b0 100644
--- a/flang/runtime/unit.cpp
+++ b/flang/runtime/unit.cpp
@@ -893,6 +893,12 @@ void ExternalFileUnit::BackspaceVariableFormattedRecord(
 }
 
 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 @@ void ExternalFileUnit::DoEndfile(IoErrorHandler &handler) {
   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;


        


More information about the flang-commits mailing list