[flang-commits] [PATCH] D120838: [flang] Catch READ/WRITE on direct-access file without REC=

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Wed Mar 2 12:38:33 PST 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG507f7317a0db: [flang] Catch READ/WRITE on direct-access file without REC= (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/D120838/new/

https://reviews.llvm.org/D120838

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


Index: flang/runtime/unit.h
===================================================================
--- flang/runtime/unit.h
+++ flang/runtime/unit.h
@@ -71,6 +71,7 @@
     if constexpr (!std::is_same_v<A, OpenStatementState>) {
       state.mutableModes() = ConnectionState::modes;
     }
+    directAccessRecWasSet_ = false;
     io_.emplace(state);
     return *io_;
   }
@@ -112,11 +113,13 @@
   void DoImpliedEndfile(IoErrorHandler &);
   void DoEndfile(IoErrorHandler &);
   void CommitWrites();
+  bool CheckDirectAccess(IoErrorHandler &);
 
   int unitNumber_{-1};
   Direction direction_{Direction::Output};
   bool impliedEndfile_{false}; // sequential/stream output has taken place
   bool beganReadingRecord_{false};
+  bool directAccessRecWasSet_{false}; // REC= appeared
 
   Lock lock_;
 
Index: flang/runtime/unit.cpp
===================================================================
--- flang/runtime/unit.cpp
+++ flang/runtime/unit.cpp
@@ -310,6 +310,7 @@
     handler.SignalError(IostatWriteAfterEndfile);
     return false;
   }
+  CheckDirectAccess(handler);
   WriteFrame(frameOffsetInFile_, recordOffsetInFrame_ + furthestAfter, handler);
   if (positionInRecord > furthestPositionInRecord) {
     std::memset(Frame() + recordOffsetInFrame_ + furthestPositionInRecord, ' ',
@@ -432,7 +433,7 @@
   if (!beganReadingRecord_) {
     beganReadingRecord_ = true;
     if (access == Access::Direct) {
-      RUNTIME_CHECK(handler, openRecl);
+      CheckDirectAccess(handler);
       auto need{static_cast<std::size_t>(recordOffsetInFrame_ + *openRecl)};
       auto got{ReadFrame(frameOffsetInFile_, need, handler)};
       if (got >= need) {
@@ -654,6 +655,9 @@
   DoImpliedEndfile(handler);
   frameOffsetInFile_ = pos;
   recordOffsetInFrame_ = 0;
+  if (access == Access::Direct) {
+    directAccessRecWasSet_ = true;
+  }
   BeginRecord();
 }
 
@@ -846,6 +850,17 @@
   BeginRecord();
 }
 
+bool ExternalFileUnit::CheckDirectAccess(IoErrorHandler &handler) {
+  if (access == Access::Direct) {
+    RUNTIME_CHECK(handler, openRecl);
+    if (!directAccessRecWasSet_) {
+      handler.SignalError("No REC= was specified for a data transfer with ACCESS='DIRECT'");
+      return false;
+    }
+  }
+  return true;
+}
+
 ChildIo &ExternalFileUnit::PushChildIo(IoStatementState &parent) {
   OwningPtr<ChildIo> current{std::move(child_)};
   Terminator &terminator{parent.GetIoErrorHandler()};


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120838.412511.patch
Type: text/x-patch
Size: 2410 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220302/4a246e75/attachment.bin>


More information about the flang-commits mailing list