Skip to content

Conversation

@klausler
Copy link
Contributor

... as a legacy spelling for OPEN(..., FORM="UNFORMATTED", ACCESS="STREAM").

... as a legacy spelling for OPEN(..., FORM="UNFORMATTED", ACCESS="STREAM").
@klausler klausler requested a review from vdonaldson January 28, 2025 00:04
@llvmbot llvmbot added flang:runtime flang Flang issues not falling into any other category flang:semantics labels Jan 28, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 28, 2025

@llvm/pr-subscribers-flang-runtime

Author: Peter Klausler (klausler)

Changes

... as a legacy spelling for OPEN(..., FORM="UNFORMATTED", ACCESS="STREAM").


Full diff: https://github.com/llvm/llvm-project/pull/124657.diff

3 Files Affected:

  • (modified) flang/docs/Extensions.md (+2)
  • (modified) flang/lib/Semantics/check-io.cpp (+1-1)
  • (modified) flang/runtime/io-api.cpp (+5-1)
diff --git a/flang/docs/Extensions.md b/flang/docs/Extensions.md
index f25f0d1e0ca392..e84bceee5ca7c7 100644
--- a/flang/docs/Extensions.md
+++ b/flang/docs/Extensions.md
@@ -411,6 +411,8 @@ end
   is accepted before an array specification (`ch*3(2)`) as well
   as afterwards.
 * A zero field width is allowed for logical formatted output (`L0`).
+* `OPEN(..., FORM='BINARY')` is accepted as a legacy synonym for
+  the standard `OPEN(..., FORM='UNFORMATTED', ACCESS='STREAM')`.
 
 ### Extensions supported when enabled by options
 
diff --git a/flang/lib/Semantics/check-io.cpp b/flang/lib/Semantics/check-io.cpp
index 3c99163c1f134f..42c3b9e11efc1b 100644
--- a/flang/lib/Semantics/check-io.cpp
+++ b/flang/lib/Semantics/check-io.cpp
@@ -920,7 +920,7 @@ void IoChecker::CheckStringValue(IoSpecKind specKind, const std::string &value,
       {IoSpecKind::Decimal, {"COMMA", "POINT"}},
       {IoSpecKind::Delim, {"APOSTROPHE", "NONE", "QUOTE"}},
       {IoSpecKind::Encoding, {"DEFAULT", "UTF-8"}},
-      {IoSpecKind::Form, {"FORMATTED", "UNFORMATTED"}},
+      {IoSpecKind::Form, {"FORMATTED", "UNFORMATTED", "BINARY"}},
       {IoSpecKind::Pad, {"NO", "YES"}},
       {IoSpecKind::Position, {"APPEND", "ASIS", "REWIND"}},
       {IoSpecKind::Round,
diff --git a/flang/runtime/io-api.cpp b/flang/runtime/io-api.cpp
index 9dfa09ab332c2a..dc3f6f87fc21b0 100644
--- a/flang/runtime/io-api.cpp
+++ b/flang/runtime/io-api.cpp
@@ -887,7 +887,7 @@ bool IODEF(SetForm)(Cookie cookie, const char *keyword, std::size_t length) {
     io.GetIoErrorHandler().Crash(
         "SetForm() called after GetNewUnit() for an OPEN statement");
   }
-  static const char *keywords[]{"FORMATTED", "UNFORMATTED", nullptr};
+  static const char *keywords[]{"FORMATTED", "UNFORMATTED", "BINARY", nullptr};
   switch (IdentifyValue(keyword, length, keywords)) {
   case 0:
     open->set_isUnformatted(false);
@@ -895,6 +895,10 @@ bool IODEF(SetForm)(Cookie cookie, const char *keyword, std::size_t length) {
   case 1:
     open->set_isUnformatted(true);
     break;
+  case 2: // legacy FORM='BINARY' means an unformatted stream
+    open->set_isUnformatted(true);
+    open->set_access(Access::Stream);
+    break;
   default:
     open->SignalError(IostatErrorInKeyword, "Invalid FORM='%.*s'",
         static_cast<int>(length), keyword);

@llvmbot
Copy link
Member

llvmbot commented Jan 28, 2025

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

Changes

... as a legacy spelling for OPEN(..., FORM="UNFORMATTED", ACCESS="STREAM").


Full diff: https://github.com/llvm/llvm-project/pull/124657.diff

3 Files Affected:

  • (modified) flang/docs/Extensions.md (+2)
  • (modified) flang/lib/Semantics/check-io.cpp (+1-1)
  • (modified) flang/runtime/io-api.cpp (+5-1)
diff --git a/flang/docs/Extensions.md b/flang/docs/Extensions.md
index f25f0d1e0ca392..e84bceee5ca7c7 100644
--- a/flang/docs/Extensions.md
+++ b/flang/docs/Extensions.md
@@ -411,6 +411,8 @@ end
   is accepted before an array specification (`ch*3(2)`) as well
   as afterwards.
 * A zero field width is allowed for logical formatted output (`L0`).
+* `OPEN(..., FORM='BINARY')` is accepted as a legacy synonym for
+  the standard `OPEN(..., FORM='UNFORMATTED', ACCESS='STREAM')`.
 
 ### Extensions supported when enabled by options
 
diff --git a/flang/lib/Semantics/check-io.cpp b/flang/lib/Semantics/check-io.cpp
index 3c99163c1f134f..42c3b9e11efc1b 100644
--- a/flang/lib/Semantics/check-io.cpp
+++ b/flang/lib/Semantics/check-io.cpp
@@ -920,7 +920,7 @@ void IoChecker::CheckStringValue(IoSpecKind specKind, const std::string &value,
       {IoSpecKind::Decimal, {"COMMA", "POINT"}},
       {IoSpecKind::Delim, {"APOSTROPHE", "NONE", "QUOTE"}},
       {IoSpecKind::Encoding, {"DEFAULT", "UTF-8"}},
-      {IoSpecKind::Form, {"FORMATTED", "UNFORMATTED"}},
+      {IoSpecKind::Form, {"FORMATTED", "UNFORMATTED", "BINARY"}},
       {IoSpecKind::Pad, {"NO", "YES"}},
       {IoSpecKind::Position, {"APPEND", "ASIS", "REWIND"}},
       {IoSpecKind::Round,
diff --git a/flang/runtime/io-api.cpp b/flang/runtime/io-api.cpp
index 9dfa09ab332c2a..dc3f6f87fc21b0 100644
--- a/flang/runtime/io-api.cpp
+++ b/flang/runtime/io-api.cpp
@@ -887,7 +887,7 @@ bool IODEF(SetForm)(Cookie cookie, const char *keyword, std::size_t length) {
     io.GetIoErrorHandler().Crash(
         "SetForm() called after GetNewUnit() for an OPEN statement");
   }
-  static const char *keywords[]{"FORMATTED", "UNFORMATTED", nullptr};
+  static const char *keywords[]{"FORMATTED", "UNFORMATTED", "BINARY", nullptr};
   switch (IdentifyValue(keyword, length, keywords)) {
   case 0:
     open->set_isUnformatted(false);
@@ -895,6 +895,10 @@ bool IODEF(SetForm)(Cookie cookie, const char *keyword, std::size_t length) {
   case 1:
     open->set_isUnformatted(true);
     break;
+  case 2: // legacy FORM='BINARY' means an unformatted stream
+    open->set_isUnformatted(true);
+    open->set_access(Access::Stream);
+    break;
   default:
     open->SignalError(IostatErrorInKeyword, "Invalid FORM='%.*s'",
         static_cast<int>(length), keyword);

@klausler klausler merged commit 8d8a821 into llvm:main Jan 31, 2025
13 checks passed
@klausler klausler deleted the bug192 branch January 31, 2025 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flang:runtime flang:semantics flang Flang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants