[flang-commits] [PATCH] D102350: flang] Support legacy extension OPEN(ACCESS='APPEND')

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Thu May 13 11:52:04 PDT 2021


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG72abc199772c: [flang] Support legacy extension OPEN(ACCESS='APPEND') (authored by klausler).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102350/new/

https://reviews.llvm.org/D102350

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


Index: flang/runtime/io-api.cpp
===================================================================
--- flang/runtime/io-api.cpp
+++ flang/runtime/io-api.cpp
@@ -589,7 +589,8 @@
     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 @@
   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);
Index: flang/lib/Semantics/check-io.cpp
===================================================================
--- flang/lib/Semantics/check-io.cpp
+++ flang/lib/Semantics/check-io.cpp
@@ -831,9 +831,16 @@
       {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);
+    }
   }
 }
 
Index: flang/include/flang/Common/Fortran-features.h
===================================================================
--- flang/include/flang/Common/Fortran-features.h
+++ flang/include/flang/Common/Fortran-features.h
@@ -30,7 +30,7 @@
     EquivalenceNumericWithCharacter, AdditionalIntrinsics, AnonymousParents,
     OldLabelDoEndStatements, LogicalIntegerAssignment, EmptySourceFile,
     ProgramReturn, ImplicitNoneTypeNever, ImplicitNoneTypeAlways,
-    ForwardRefDummyImplicitNone)
+    ForwardRefDummyImplicitNone, OpenAccessAppend)
 
 using LanguageFeatures = EnumSet<LanguageFeature, LanguageFeature_enumSize>;
 
Index: flang/docs/Extensions.md
===================================================================
--- flang/docs/Extensions.md
+++ flang/docs/Extensions.md
@@ -134,6 +134,8 @@
   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
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102350.345240.patch
Type: text/x-patch
Size: 3136 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20210513/dd7ba555/attachment.bin>


More information about the flang-commits mailing list