[flang-commits] [PATCH] D127029: [flang][runtime] Fix WRITE after OPEN(.., POSITION="APPEND")

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Sat Jun 4 09:25:40 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG9a163ffe1a50: [flang][runtime] Fix WRITE after OPEN(.., ACCESS="APPEND") (authored by klausler).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127029

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


Index: flang/runtime/unit.cpp
===================================================================
--- flang/runtime/unit.cpp
+++ flang/runtime/unit.cpp
@@ -137,7 +137,7 @@
           "OPEN(UNIT=%d,ACCESS='DIRECT',RECL=%jd): record length is invalid",
           unitNumber(), static_cast<std::intmax_t>(*openRecl));
     } else if (totalBytes && (*totalBytes % *openRecl != 0)) {
-      handler.SignalError(IostatOpenBadAppend,
+      handler.SignalError(IostatOpenBadRecl,
           "OPEN(UNIT=%d,ACCESS='DIRECT',RECL=%jd): record length is not an "
           "even divisor of the file size %jd",
           unitNumber(), static_cast<std::intmax_t>(*openRecl),
@@ -150,12 +150,17 @@
   if (totalBytes && access == Access::Direct && openRecl.value_or(0) > 0) {
     endfileRecordNumber = 1 + (*totalBytes / *openRecl);
   }
-  if (position == Position::Append && access != Access::Stream) {
-    if (!endfileRecordNumber) {
-      // Fake it so that we can backspace relative from the end
-      endfileRecordNumber = std::numeric_limits<std::int64_t>::max() - 2;
+  if (position == Position::Append) {
+    if (totalBytes) {
+      frameOffsetInFile_ = *totalBytes;
+    }
+    if (access != Access::Stream) {
+      if (!endfileRecordNumber) {
+        // Fake it so that we can backspace relative from the end
+        endfileRecordNumber = std::numeric_limits<std::int64_t>::max() - 2;
+      }
+      currentRecordNumber = *endfileRecordNumber;
     }
-    currentRecordNumber = *endfileRecordNumber;
   }
 }
 
Index: flang/runtime/file.cpp
===================================================================
--- flang/runtime/file.cpp
+++ flang/runtime/file.cpp
@@ -132,7 +132,7 @@
   RUNTIME_CHECK(handler, action.has_value());
   pending_.reset();
   if (position == Position::Append && !RawSeekToEnd()) {
-    handler.SignalErrno();
+    handler.SignalError(IostatOpenBadAppend);
   }
   isTerminal_ = ::isatty(fd_) == 1;
   mayRead_ = *action != Action::Write;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127029.434270.patch
Type: text/x-patch
Size: 1973 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220604/892e85c4/attachment-0001.bin>


More information about the flang-commits mailing list