[flang-commits] [PATCH] D88612: flang] Fix buffering read->write transition

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Wed Sep 30 13:13:22 PDT 2020


klausler created this revision.
klausler added a reviewer: schweitz.
klausler added a project: Flang.
Herald added a reviewer: jdoerfert.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
klausler requested review of this revision.

The buffer needs to be Reset() after a Flush(), since the
Flush() can be a no-op after a read->write transition.
And record numbers are 1-based, not 0-based.
This fixes a bug with rewrites of records that have been
recently read.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88612

Files:
  flang/runtime/buffer.h
  flang/runtime/io-api.cpp


Index: flang/runtime/io-api.cpp
===================================================================
--- flang/runtime/io-api.cpp
+++ flang/runtime/io-api.cpp
@@ -517,7 +517,7 @@
   }
   connection.currentRecordNumber = rec;
   if (auto *unit{io.GetExternalFileUnit()}) {
-    unit->SetPosition(rec * *connection.recordLength);
+    unit->SetPosition((rec - 1) * *connection.recordLength);
   }
   return true;
 }
Index: flang/runtime/buffer.h
===================================================================
--- flang/runtime/buffer.h
+++ flang/runtime/buffer.h
@@ -94,7 +94,7 @@
         start_ + (at - fileOffset_) + static_cast<std::int64_t>(bytes) >
             size_) {
       Flush(handler);
-      fileOffset_ = at;
+      Reset(at);
       Reallocate(bytes, handler);
     }
     dirty_ = true;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88612.295387.patch
Type: text/x-patch
Size: 807 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20200930/127aeb18/attachment.bin>


More information about the flang-commits mailing list