[flang-commits] [PATCH] D106321: [flang] Don't require newline at EOF in unformatted sequential runtime input

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Tue Jul 20 15:25:21 PDT 2021


This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb43e083bb6b1: [flang] Don't require newline at EOF in unformatted sequential runtime input (authored by klausler).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106321

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


Index: flang/runtime/unit.cpp
===================================================================
--- flang/runtime/unit.cpp
+++ flang/runtime/unit.cpp
@@ -341,19 +341,22 @@
 bool ExternalFileUnit::SetSequentialVariableFormattedRecordLength() {
   if (recordLength || access != Access::Sequential) {
     return true;
-  }
-  if (FrameLength() > recordOffsetInFrame_) {
+  } else if (FrameLength() > recordOffsetInFrame_) {
     const char *record{Frame() + recordOffsetInFrame_};
-    if (const char *nl{reinterpret_cast<const char *>(
-            std::memchr(record, '\n', FrameLength() - recordOffsetInFrame_))}) {
+    std::size_t bytes{FrameLength() - recordOffsetInFrame_};
+    if (const char *nl{
+            reinterpret_cast<const char *>(std::memchr(record, '\n', bytes))}) {
       recordLength = nl - record;
       if (*recordLength > 0 && record[*recordLength - 1] == '\r') {
         --*recordLength;
       }
-      return true;
+    } else {
+      recordLength = bytes; // final record w/o \n
     }
+    return true;
+  } else {
+    return false;
   }
-  return false;
 }
 
 void ExternalFileUnit::SetLeftTabLimit() {
@@ -413,8 +416,10 @@
         if (Frame()[recordOffsetInFrame_ + *recordLength] == '\r') {
           ++recordOffsetInFrame_;
         }
-        recordOffsetInFrame_ += *recordLength + 1;
-        RUNTIME_CHECK(handler, Frame()[recordOffsetInFrame_ - 1] == '\n');
+        if (Frame()[recordOffsetInFrame_ + *recordLength] == '\n') {
+          ++recordOffsetInFrame_;
+        }
+        recordOffsetInFrame_ += *recordLength;
         recordLength.reset();
       }
     }
Index: flang/runtime/file.cpp
===================================================================
--- flang/runtime/file.cpp
+++ flang/runtime/file.cpp
@@ -199,7 +199,6 @@
   while (got < minBytes) {
     auto chunk{::read(fd_, buffer + got, maxBytes - got)};
     if (chunk == 0) {
-      handler.SignalEnd();
       break;
     } else if (chunk < 0) {
       auto err{errno};


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106321.360296.patch
Type: text/x-patch
Size: 1994 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20210720/d7cfd1ad/attachment-0001.bin>


More information about the flang-commits mailing list