Skip to content

Commit 8d8a821

Browse files
authored
[flang] Support OPEN(..., FORM="BINARY") (#124657)
... as a legacy spelling for OPEN(..., FORM="UNFORMATTED", ACCESS="STREAM").
1 parent ef91cae commit 8d8a821

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

flang/docs/Extensions.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,8 @@ end
411411
is accepted before an array specification (`ch*3(2)`) as well
412412
as afterwards.
413413
* A zero field width is allowed for logical formatted output (`L0`).
414+
* `OPEN(..., FORM='BINARY')` is accepted as a legacy synonym for
415+
the standard `OPEN(..., FORM='UNFORMATTED', ACCESS='STREAM')`.
414416

415417
### Extensions supported when enabled by options
416418

flang/lib/Semantics/check-io.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ void IoChecker::CheckStringValue(IoSpecKind specKind, const std::string &value,
920920
{IoSpecKind::Decimal, {"COMMA", "POINT"}},
921921
{IoSpecKind::Delim, {"APOSTROPHE", "NONE", "QUOTE"}},
922922
{IoSpecKind::Encoding, {"DEFAULT", "UTF-8"}},
923-
{IoSpecKind::Form, {"FORMATTED", "UNFORMATTED"}},
923+
{IoSpecKind::Form, {"FORMATTED", "UNFORMATTED", "BINARY"}},
924924
{IoSpecKind::Pad, {"NO", "YES"}},
925925
{IoSpecKind::Position, {"APPEND", "ASIS", "REWIND"}},
926926
{IoSpecKind::Round,

flang/runtime/io-api.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,14 +887,18 @@ bool IODEF(SetForm)(Cookie cookie, const char *keyword, std::size_t length) {
887887
io.GetIoErrorHandler().Crash(
888888
"SetForm() called after GetNewUnit() for an OPEN statement");
889889
}
890-
static const char *keywords[]{"FORMATTED", "UNFORMATTED", nullptr};
890+
static const char *keywords[]{"FORMATTED", "UNFORMATTED", "BINARY", nullptr};
891891
switch (IdentifyValue(keyword, length, keywords)) {
892892
case 0:
893893
open->set_isUnformatted(false);
894894
break;
895895
case 1:
896896
open->set_isUnformatted(true);
897897
break;
898+
case 2: // legacy FORM='BINARY' means an unformatted stream
899+
open->set_isUnformatted(true);
900+
open->set_access(Access::Stream);
901+
break;
898902
default:
899903
open->SignalError(IostatErrorInKeyword, "Invalid FORM='%.*s'",
900904
static_cast<int>(length), keyword);

0 commit comments

Comments
 (0)