Skip to content

Commit 72abc19

Browse files
committed
[flang] Support legacy extension OPEN(ACCESS='APPEND')
It should of course be POSITION='APPEND' but Sun Fortran supported it on ACCESS=. Differential Revision: https://reviews.llvm.org/D102350
1 parent fe319a8 commit 72abc19

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

flang/docs/Extensions.md

+2
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ accepted if enabled by command-line options.
134134
bound, in a scope with IMPLICIT NONE(TYPE) if the name
135135
of the dummy argument would have caused it to be implicitly typed
136136
as default INTEGER if IMPLICIT NONE(TYPE) were absent.
137+
* OPEN(ACCESS='APPEND') is interpreted as OPEN(POSITION='APPEND')
138+
to ease porting from Sun Fortran.
137139

138140
### Extensions supported when enabled by options
139141

flang/include/flang/Common/Fortran-features.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ ENUM_CLASS(LanguageFeature, BackslashEscapes, OldDebugLines,
3030
EquivalenceNumericWithCharacter, AdditionalIntrinsics, AnonymousParents,
3131
OldLabelDoEndStatements, LogicalIntegerAssignment, EmptySourceFile,
3232
ProgramReturn, ImplicitNoneTypeNever, ImplicitNoneTypeAlways,
33-
ForwardRefDummyImplicitNone)
33+
ForwardRefDummyImplicitNone, OpenAccessAppend)
3434

3535
using LanguageFeatures = EnumSet<LanguageFeature, LanguageFeature_enumSize>;
3636

flang/lib/Semantics/check-io.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -831,9 +831,16 @@ void IoChecker::CheckStringValue(IoSpecKind specKind, const std::string &value,
831831
{IoSpecKind::Convert, {"BIG_ENDIAN", "LITTLE_ENDIAN", "NATIVE"}},
832832
{IoSpecKind::Dispose, {"DELETE", "KEEP"}},
833833
};
834-
if (!specValues.at(specKind).count(parser::ToUpperCaseLetters(value))) {
835-
context_.Say(source, "Invalid %s value '%s'"_err_en_US,
836-
parser::ToUpperCaseLetters(common::EnumToString(specKind)), value);
834+
auto upper{parser::ToUpperCaseLetters(value)};
835+
if (specValues.at(specKind).count(upper) == 0) {
836+
if (specKind == IoSpecKind::Access && upper == "APPEND" &&
837+
context_.languageFeatures().ShouldWarn(
838+
common::LanguageFeature::OpenAccessAppend)) {
839+
context_.Say(source, "ACCESS='%s' interpreted as POSITION='%s'"_en_US, value, upper);
840+
} else {
841+
context_.Say(source, "Invalid %s value '%s'"_err_en_US,
842+
parser::ToUpperCaseLetters(common::EnumToString(specKind)), value);
843+
}
837844
}
838845
}
839846

flang/runtime/io-api.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,8 @@ bool IONAME(SetAccess)(Cookie cookie, const char *keyword, std::size_t length) {
589589
io.GetIoErrorHandler().Crash(
590590
"SetAccess() called when not in an OPEN statement");
591591
}
592-
static const char *keywords[]{"SEQUENTIAL", "DIRECT", "STREAM", nullptr};
592+
static const char *keywords[]{
593+
"SEQUENTIAL", "DIRECT", "STREAM", "APPEND", nullptr};
593594
switch (IdentifyValue(keyword, length, keywords)) {
594595
case 0:
595596
open->set_access(Access::Sequential);
@@ -600,6 +601,9 @@ bool IONAME(SetAccess)(Cookie cookie, const char *keyword, std::size_t length) {
600601
case 2:
601602
open->set_access(Access::Stream);
602603
break;
604+
case 3: // Sun Fortran extension ACCESS=APPEND: treat as if POSITION=APPEND
605+
open->set_position(Position::Append);
606+
break;
603607
default:
604608
open->SignalError(IostatErrorInKeyword, "Invalid ACCESS='%.*s'",
605609
static_cast<int>(length), keyword);

0 commit comments

Comments
 (0)