Skip to content

Commit 2eb81ad

Browse files
committed
[flang] Set default form if unspecified at end of OPEN statement
The standard specifies that the form must be set to a default at the end of an open statement (C.7.4 point 2) where it was not specified. Only in the case of a pre-connected unit can the form be deferred until the first data transfer statement. Set back the default form setting in OpenStatementState::EndIoStatement that had been removed when deferring the pre-connected unit from setting in 199a623. Also return "UNDEFINED" instead of "UNKNOWN" to the FORM inquiry when the form was not yet specified as defined in 12.10.2.12. Related test: syntax 215a216. Differential Revision: https://reviews.llvm.org/D108990
1 parent 4576068 commit 2eb81ad

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

flang/runtime/io-stmt.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ int OpenStatementState::EndIoStatement() {
243243
}
244244
unit().isUnformatted = *isUnformatted_;
245245
}
246+
if (!unit().isUnformatted) {
247+
// Set default format (C.7.4 point 2).
248+
unit().isUnformatted = unit().access != Access::Sequential;
249+
}
246250
return ExternalIoStatementBase::EndIoStatement();
247251
}
248252

@@ -969,7 +973,7 @@ bool InquireUnitState::Inquire(
969973
: "ASCII";
970974
break;
971975
case HashInquiryKeyword("FORM"):
972-
str = !unit().isUnformatted ? "UNKNOWN"
976+
str = !unit().isUnformatted ? "UNDEFINED"
973977
: *unit().isUnformatted ? "UNFORMATTED"
974978
: "FORMATTED";
975979
break;

0 commit comments

Comments
 (0)