[flang-commits] [PATCH] D129673: [flang][runtime] Keep frame buffer in sync with file when truncating

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Wed Jul 13 16:16:35 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG1a65d09dcf9b: [flang][runtime] Keep frame buffer in sync with file when truncating (authored by klausler).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129673

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


Index: flang/runtime/unit.cpp
===================================================================
--- flang/runtime/unit.cpp
+++ flang/runtime/unit.cpp
@@ -898,9 +898,9 @@
   }
   frameOffsetInFile_ += recordOffsetInFrame_ + furthestPositionInRecord;
   recordOffsetInFrame_ = 0;
-  // Flush (if dirty) and reset the frame (even if reading)
-  WriteFrame(frameOffsetInFile_, 0, handler);
+  FlushOutput(handler);
   Truncate(frameOffsetInFile_, handler);
+  TruncateFrame(frameOffsetInFile_, handler);
   BeginRecord();
   impliedEndfile_ = false;
 }
Index: flang/runtime/buffer.h
===================================================================
--- flang/runtime/buffer.h
+++ flang/runtime/buffer.h
@@ -128,6 +128,15 @@
     }
   }
 
+  void TruncateFrame(std::int64_t at, IoErrorHandler &handler) {
+    RUNTIME_CHECK(handler, !dirty_);
+    if (at <= fileOffset_) {
+      Reset(at);
+    } else if (at < fileOffset_ + length_) {
+      length_ = at - fileOffset_;
+    }
+  }
+
 private:
   STORE &Store() { return static_cast<STORE &>(*this); }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129673.444444.patch
Type: text/x-patch
Size: 1055 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220713/c44a6b7c/attachment.bin>


More information about the flang-commits mailing list