[flang-commits] [PATCH] D126146: [flang][runtime] Handle BACKSPACE after reading past EOF

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Tue May 24 10:28:15 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG8527f9e4437f: [flang][runtime] Handle BACKSPACE after reading past EOF (authored by klausler).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126146

Files:
  flang/runtime/unit.cpp
  flang/runtime/unit.h


Index: flang/runtime/unit.h
===================================================================
--- flang/runtime/unit.h
+++ flang/runtime/unit.h
@@ -115,6 +115,7 @@
   void DoEndfile(IoErrorHandler &);
   void CommitWrites();
   bool CheckDirectAccess(IoErrorHandler &);
+  void HitEndOnRead(IoErrorHandler &);
 
   int unitNumber_{-1};
   Direction direction_{Direction::Output};
Index: flang/runtime/unit.cpp
===================================================================
--- flang/runtime/unit.cpp
+++ flang/runtime/unit.cpp
@@ -348,10 +348,7 @@
     furthestPositionInRecord = furthestAfter;
     return true;
   } else {
-    handler.SignalEnd();
-    if (IsRecordFile() && access != Access::Direct) {
-      endfileRecordNumber = currentRecordNumber;
-    }
+    HitEndOnRead(handler);
     return false;
   }
 }
@@ -384,10 +381,7 @@
     if (got >= need) {
       return Frame() + at;
     }
-    handler.SignalEnd();
-    if (IsRecordFile() && access != Access::Direct) {
-      endfileRecordNumber = currentRecordNumber;
-    }
+    HitEndOnRead(handler);
   }
   return nullptr;
 }
@@ -422,7 +416,7 @@
         recordLength = openRecl;
       } else {
         recordLength.reset();
-        handler.SignalEnd();
+        HitEndOnRead(handler);
       }
     } else {
       recordLength.reset();
@@ -667,7 +661,7 @@
   const char *error{nullptr};
   if (got < need) {
     if (got == recordOffsetInFrame_) {
-      handler.SignalEnd();
+      HitEndOnRead(handler);
     } else {
       error = "Unformatted variable-length sequential file input failed at "
               "record #%jd (file offset %jd): truncated record header";
@@ -722,7 +716,7 @@
         recordLength = length;
         unterminatedRecord = true;
       } else {
-        handler.SignalEnd();
+        HitEndOnRead(handler);
       }
       break;
     }
@@ -878,6 +872,13 @@
   return true;
 }
 
+void ExternalFileUnit::HitEndOnRead(IoErrorHandler &handler) {
+  handler.SignalEnd();
+  if (IsRecordFile() && access != Access::Direct) {
+    endfileRecordNumber = currentRecordNumber;
+  }
+}
+
 ChildIo &ExternalFileUnit::PushChildIo(IoStatementState &parent) {
   OwningPtr<ChildIo> current{std::move(child_)};
   Terminator &terminator{parent.GetIoErrorHandler()};


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126146.431714.patch
Type: text/x-patch
Size: 2258 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220524/6e751829/attachment.bin>


More information about the flang-commits mailing list