[flang-commits] [flang] 047884e - [flang] runtime: catch OPEN(ACCESS='DIRECT', POSITION=)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Tue Jan 18 15:08:08 PST 2022


Author: Peter Klausler
Date: 2022-01-18T14:54:53-08:00
New Revision: 047884e71e677d7814eb5e6b9b6dabfc8da6cb07

URL: https://github.com/llvm/llvm-project/commit/047884e71e677d7814eb5e6b9b6dabfc8da6cb07
DIFF: https://github.com/llvm/llvm-project/commit/047884e71e677d7814eb5e6b9b6dabfc8da6cb07.diff

LOG: [flang] runtime: catch OPEN(ACCESS='DIRECT',POSITION=)

A POSITION= specifier may not be used on a direct access file.

Differential Revision: https://reviews.llvm.org/D117596

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/flang/runtime/io-api.cpp b/flang/runtime/io-api.cpp
index 88a5c3b6b5844..811095417ffb8 100644
--- a/flang/runtime/io-api.cpp
+++ b/flang/runtime/io-api.cpp
@@ -519,7 +519,7 @@ bool IONAME(SetPos)(Cookie cookie, std::int64_t pos) {
   ConnectionState &connection{io.GetConnectionState()};
   if (connection.access != Access::Stream) {
     io.GetIoErrorHandler().SignalError(
-        "REC= may not appear unless ACCESS='STREAM'");
+        "POS= may not appear unless ACCESS='STREAM'");
     return false;
   }
   if (pos < 1) {

diff  --git a/flang/runtime/io-stmt.cpp b/flang/runtime/io-stmt.cpp
index e4aed8d0c724f..0a544d69958bf 100644
--- a/flang/runtime/io-stmt.cpp
+++ b/flang/runtime/io-stmt.cpp
@@ -208,20 +208,30 @@ void OpenStatementState::set_path(const char *path, std::size_t length) {
 }
 
 int OpenStatementState::EndIoStatement() {
+  if (position_) {
+    if (access_ && *access_ == Access::Direct) {
+      SignalError("POSITION= may not be set with ACCESS='DIRECT'");
+      position_.reset();
+    }
+  }
   if (path_.get() || wasExtant_ ||
       (status_ && *status_ == OpenStatus::Scratch)) {
-    unit().OpenUnit(status_, action_, position_, std::move(path_), pathLength_,
-        convert_, *this);
+    unit().OpenUnit(status_, action_, position_.value_or(Position::AsIs),
+        std::move(path_), pathLength_, convert_, *this);
   } else {
-    unit().OpenAnonymousUnit(status_, action_, position_, convert_, *this);
+    unit().OpenAnonymousUnit(
+        status_, action_, position_.value_or(Position::AsIs), convert_, *this);
   }
   if (access_) {
     if (*access_ != unit().access) {
       if (wasExtant_) {
         SignalError("ACCESS= may not be changed on an open unit");
+        access_.reset();
       }
     }
-    unit().access = *access_;
+    if (access_) {
+      unit().access = *access_;
+    }
   }
   if (!unit().isUnformatted) {
     unit().isUnformatted = isUnformatted_;

diff  --git a/flang/runtime/io-stmt.h b/flang/runtime/io-stmt.h
index 065fc2f096051..bf84f4a3369a0 100644
--- a/flang/runtime/io-stmt.h
+++ b/flang/runtime/io-stmt.h
@@ -577,7 +577,7 @@ class OpenStatementState : public ExternalIoStatementBase {
 private:
   bool wasExtant_;
   std::optional<OpenStatus> status_;
-  Position position_{Position::AsIs};
+  std::optional<Position> position_;
   std::optional<Action> action_;
   Convert convert_{Convert::Native};
   OwningPtr<char> path_;


        


More information about the flang-commits mailing list