[flang-commits] [flang] 61687f3 - [flang] Fix buffering read->write transition

peter klausler via flang-commits flang-commits at lists.llvm.org
Thu Oct 1 17:14:46 PDT 2020


Author: peter klausler
Date: 2020-10-01T16:57:38-07:00
New Revision: 61687f3a48c254436cbdd55e10bfb23b727f3eb5

URL: https://github.com/llvm/llvm-project/commit/61687f3a48c254436cbdd55e10bfb23b727f3eb5
DIFF: https://github.com/llvm/llvm-project/commit/61687f3a48c254436cbdd55e10bfb23b727f3eb5.diff

LOG: [flang] Fix buffering read->write transition

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.

Differential revision: https://reviews.llvm.org/D88612

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/flang/runtime/buffer.h b/flang/runtime/buffer.h
index 27e0ac31579d..c5bd5aedaaee 100644
--- a/flang/runtime/buffer.h
+++ b/flang/runtime/buffer.h
@@ -94,7 +94,7 @@ template <typename STORE> class FileFrame {
         start_ + (at - fileOffset_) + static_cast<std::int64_t>(bytes) >
             size_) {
       Flush(handler);
-      fileOffset_ = at;
+      Reset(at);
       Reallocate(bytes, handler);
     }
     dirty_ = true;

diff  --git a/flang/runtime/io-api.cpp b/flang/runtime/io-api.cpp
index edd338af0fa7..0dcfabd2d8ce 100644
--- a/flang/runtime/io-api.cpp
+++ b/flang/runtime/io-api.cpp
@@ -518,7 +518,7 @@ bool IONAME(SetRec)(Cookie cookie, std::int64_t rec) {
   }
   connection.currentRecordNumber = rec;
   if (auto *unit{io.GetExternalFileUnit()}) {
-    unit->SetPosition(rec * *connection.recordLength);
+    unit->SetPosition((rec - 1) * *connection.recordLength);
   }
   return true;
 }


        


More information about the flang-commits mailing list