[flang-commits] [PATCH] D88673: [flang] Fix INQUIRE of access and formatting possibilities

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Thu Oct 1 09:45:41 PDT 2020


klausler created this revision.
klausler added a reviewer: PeteSteinfeld.
klausler added a project: Flang.
Herald added a reviewer: jdoerfert.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
klausler requested review of this revision.

Don't give false positives from INQUIRE about possible
access mode changes on connected units.  DIRECT and SEQUENTIAL
cannot be intermixed, apart from allowing DIRECT on a SEQUENTIAL
file with fixed-size records and positioning.  Nor can
FORMATTED and UNFORMATTED be interchanged.  On unconnected
files, the best that we can do is "UNKNOWN".


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88673

Files:
  flang/runtime/io-stmt.cpp


Index: flang/runtime/io-stmt.cpp
===================================================================
--- flang/runtime/io-stmt.cpp
+++ flang/runtime/io-stmt.cpp
@@ -820,7 +820,10 @@
     }
     break;
   case HashInquiryKeyword("DIRECT"):
-    str = unit().mayPosition() ? "YES" : "NO";
+    str = unit().access == Access::Direct ||
+            (unit().mayPosition() && unit().isFixedRecordLength)
+        ? "YES"
+        : "NO";
     break;
   case HashInquiryKeyword("ENCODING"):
     str = unit().isUnformatted ? "UNDEFINED"
@@ -831,7 +834,7 @@
     str = unit().isUnformatted ? "UNFORMATTED" : "FORMATTED";
     break;
   case HashInquiryKeyword("FORMATTED"):
-    str = "YES";
+    str = !unit().isUnformatted ? "YES" : "NO";
     break;
   case HashInquiryKeyword("NAME"):
     str = unit().path();
@@ -887,7 +890,9 @@
     }
     break;
   case HashInquiryKeyword("SEQUENTIAL"):
-    str = "YES";
+    // "NO" for Direct, since Sequential would not work if
+    // the unit were reopened without RECL=.
+    str = unit().access == Access::Sequential ? "YES" : "NO";
     break;
   case HashInquiryKeyword("SIGN"):
     str = unit().isUnformatted                 ? "UNDEFINED"
@@ -895,13 +900,13 @@
                                                : "SUPPRESS";
     break;
   case HashInquiryKeyword("STREAM"):
-    str = "YES";
+    str = unit().access == Access::Stream ? "YES" : "NO";
     break;
   case HashInquiryKeyword("WRITE"):
     str = unit().mayWrite() ? "YES" : "NO";
     break;
   case HashInquiryKeyword("UNFORMATTED"):
-    str = "YES";
+    str = unit().isUnformatted ? "YES" : "NO";
     break;
   }
   if (str) {
@@ -1090,6 +1095,10 @@
     break;
   case HashInquiryKeyword("DIRECT"):
   case HashInquiryKeyword("ENCODING"):
+  case HashInquiryKeyword("FORMATTED"):
+  case HashInquiryKeyword("SEQUENTIAL"):
+  case HashInquiryKeyword("STREAM"):
+  case HashInquiryKeyword("UNFORMATTED"):
     str = "UNKNONN";
     break;
   case HashInquiryKeyword("READ"):
@@ -1101,12 +1110,6 @@
   case HashInquiryKeyword("WRITE"):
     str = MayWrite(path_.get()) ? "YES" : "NO";
     break;
-  case HashInquiryKeyword("FORMATTED"):
-  case HashInquiryKeyword("SEQUENTIAL"):
-  case HashInquiryKeyword("STREAM"):
-  case HashInquiryKeyword("UNFORMATTED"):
-    str = "YES";
-    break;
   case HashInquiryKeyword("NAME"):
     str = path_.get();
     return true;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88673.295603.patch
Type: text/x-patch
Size: 2383 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20201001/645755de/attachment-0001.bin>


More information about the flang-commits mailing list