[flang-commits] [flang] c9b31da - [flang][runtime] Allow OPEN(n, ENCODING=) to change the encoding

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Mon Jul 3 11:32:50 PDT 2023


Author: Peter Klausler
Date: 2023-07-03T11:28:28-07:00
New Revision: c9b31dae56f155ed08cc855dffe7eae2ea8cd30d

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

LOG: [flang][runtime] Allow OPEN(n,ENCODING=) to change the encoding

OPEN statements can be used to change some, but not all, attributes
of units that have already been opened.  The I/O runtime library
wasn't allowing ENCODING= to be changed.  Every other Fortran compiler
permits this usage, and it's safe and useful, so allow it.
(Otherwise there's no good way to ensure that the preconnected
unit 6 is in UTF-8 mode.)

Differential Revision: https://reviews.llvm.org/D154379

Added: 
    

Modified: 
    flang/docs/Extensions.md
    flang/runtime/io-api.cpp

Removed: 
    


################################################################################
diff  --git a/flang/docs/Extensions.md b/flang/docs/Extensions.md
index eb885b3aaeb785..d3cb2f142c54b0 100644
--- a/flang/docs/Extensions.md
+++ b/flang/docs/Extensions.md
@@ -592,3 +592,7 @@ end module
 
 * `EXTENDS_TYPE_OF()` returns `.TRUE.` if both of its arguments have the
   same type, a case that is technically implementation-defined.
+
+* `ENCODING=` is not in the list of changeable modes on an I/O unit,
+  but every Fortran compiler allows the encoding to be changed on an
+  open unit.

diff  --git a/flang/runtime/io-api.cpp b/flang/runtime/io-api.cpp
index 4d569f898ea8b6..fe58bbc75f8323 100644
--- a/flang/runtime/io-api.cpp
+++ b/flang/runtime/io-api.cpp
@@ -927,25 +927,20 @@ bool IONAME(SetEncoding)(
     io.GetIoErrorHandler().Crash(
         "SetEncoding() called after GetNewUnit() for an OPEN statement");
   }
-  bool isUTF8{false};
+  // Allow the encoding to be changed on an open unit -- it's
+  // useful and safe.
   static const char *keywords[]{"UTF-8", "DEFAULT", nullptr};
   switch (IdentifyValue(keyword, length, keywords)) {
   case 0:
-    isUTF8 = true;
+    open->unit().isUTF8 = true;
     break;
   case 1:
-    isUTF8 = false;
+    open->unit().isUTF8 = false;
     break;
   default:
     open->SignalError(IostatErrorInKeyword, "Invalid ENCODING='%.*s'",
         static_cast<int>(length), keyword);
   }
-  if (isUTF8 != open->unit().isUTF8) {
-    if (open->wasExtant()) {
-      open->SignalError("ENCODING= may not be changed on an open unit");
-    }
-    open->unit().isUTF8 = isUTF8;
-  }
   return true;
 }
 


        


More information about the flang-commits mailing list