[flang-commits] [flang] 72abc19 - [flang] Support legacy extension OPEN(ACCESS='APPEND')

peter klausler via flang-commits flang-commits at lists.llvm.org
Thu May 13 11:51:46 PDT 2021


Author: peter klausler
Date: 2021-05-13T11:51:20-07:00
New Revision: 72abc199772c30ea2cffaa5dd4a8aa2bb2b7f18c

URL: https://github.com/llvm/llvm-project/commit/72abc199772c30ea2cffaa5dd4a8aa2bb2b7f18c
DIFF: https://github.com/llvm/llvm-project/commit/72abc199772c30ea2cffaa5dd4a8aa2bb2b7f18c.diff

LOG: [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

Added: 
    

Modified: 
    flang/docs/Extensions.md
    flang/include/flang/Common/Fortran-features.h
    flang/lib/Semantics/check-io.cpp
    flang/runtime/io-api.cpp

Removed: 
    


################################################################################
diff  --git a/flang/docs/Extensions.md b/flang/docs/Extensions.md
index 81c2932216889..89fca93d20820 100644
--- a/flang/docs/Extensions.md
+++ b/flang/docs/Extensions.md
@@ -134,6 +134,8 @@ accepted if enabled by command-line options.
   bound, in a scope with IMPLICIT NONE(TYPE) if the name
   of the dummy argument would have caused it to be implicitly typed
   as default INTEGER if IMPLICIT NONE(TYPE) were absent.
+* OPEN(ACCESS='APPEND') is interpreted as OPEN(POSITION='APPEND')
+  to ease porting from Sun Fortran.
 
 ### Extensions supported when enabled by options
 

diff  --git a/flang/include/flang/Common/Fortran-features.h b/flang/include/flang/Common/Fortran-features.h
index 0d8a59d8b82fc..9fed37d641b24 100644
--- a/flang/include/flang/Common/Fortran-features.h
+++ b/flang/include/flang/Common/Fortran-features.h
@@ -30,7 +30,7 @@ ENUM_CLASS(LanguageFeature, BackslashEscapes, OldDebugLines,
     EquivalenceNumericWithCharacter, AdditionalIntrinsics, AnonymousParents,
     OldLabelDoEndStatements, LogicalIntegerAssignment, EmptySourceFile,
     ProgramReturn, ImplicitNoneTypeNever, ImplicitNoneTypeAlways,
-    ForwardRefDummyImplicitNone)
+    ForwardRefDummyImplicitNone, OpenAccessAppend)
 
 using LanguageFeatures = EnumSet<LanguageFeature, LanguageFeature_enumSize>;
 

diff  --git a/flang/lib/Semantics/check-io.cpp b/flang/lib/Semantics/check-io.cpp
index 897b7fd6570a9..c0eeeafd8ace9 100644
--- a/flang/lib/Semantics/check-io.cpp
+++ b/flang/lib/Semantics/check-io.cpp
@@ -831,9 +831,16 @@ void IoChecker::CheckStringValue(IoSpecKind specKind, const std::string &value,
       {IoSpecKind::Convert, {"BIG_ENDIAN", "LITTLE_ENDIAN", "NATIVE"}},
       {IoSpecKind::Dispose, {"DELETE", "KEEP"}},
   };
-  if (!specValues.at(specKind).count(parser::ToUpperCaseLetters(value))) {
-    context_.Say(source, "Invalid %s value '%s'"_err_en_US,
-        parser::ToUpperCaseLetters(common::EnumToString(specKind)), value);
+  auto upper{parser::ToUpperCaseLetters(value)};
+  if (specValues.at(specKind).count(upper) == 0) {
+    if (specKind == IoSpecKind::Access && upper == "APPEND" &&
+        context_.languageFeatures().ShouldWarn(
+            common::LanguageFeature::OpenAccessAppend)) {
+      context_.Say(source, "ACCESS='%s' interpreted as POSITION='%s'"_en_US, value, upper);
+    } else {
+      context_.Say(source, "Invalid %s value '%s'"_err_en_US,
+          parser::ToUpperCaseLetters(common::EnumToString(specKind)), value);
+    }
   }
 }
 

diff  --git a/flang/runtime/io-api.cpp b/flang/runtime/io-api.cpp
index 9c2d436c8afa8..8754cd666ae7a 100644
--- a/flang/runtime/io-api.cpp
+++ b/flang/runtime/io-api.cpp
@@ -589,7 +589,8 @@ bool IONAME(SetAccess)(Cookie cookie, const char *keyword, std::size_t length) {
     io.GetIoErrorHandler().Crash(
         "SetAccess() called when not in an OPEN statement");
   }
-  static const char *keywords[]{"SEQUENTIAL", "DIRECT", "STREAM", nullptr};
+  static const char *keywords[]{
+      "SEQUENTIAL", "DIRECT", "STREAM", "APPEND", nullptr};
   switch (IdentifyValue(keyword, length, keywords)) {
   case 0:
     open->set_access(Access::Sequential);
@@ -600,6 +601,9 @@ bool IONAME(SetAccess)(Cookie cookie, const char *keyword, std::size_t length) {
   case 2:
     open->set_access(Access::Stream);
     break;
+  case 3: // Sun Fortran extension ACCESS=APPEND: treat as if POSITION=APPEND
+    open->set_position(Position::Append);
+    break;
   default:
     open->SignalError(IostatErrorInKeyword, "Invalid ACCESS='%.*s'",
         static_cast<int>(length), keyword);


        


More information about the flang-commits mailing list