[flang-commits] [flang] ef15617 - [flang][runtime] Return the right mutable modes from INQUIRE in child I/O

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Wed Feb 15 08:00:53 PST 2023


Author: Peter Klausler
Date: 2023-02-15T08:00:40-08:00
New Revision: ef15617f124ca5cce24be62257fc12b0a1083f8d

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

LOG: [flang][runtime] Return the right mutable modes from INQUIRE in child I/O

During child I/O -- a call to a user-defined subroutine with a generic interface
to handle read and write operations on a specific derived type -- ensure that
any INQUIRE statement probing mutable modes like BLANK= will observe changes
that have been made to those modes via control edit descriptors like BN
while processing the original I/O statement's format.

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

Added: 
    

Modified: 
    flang/runtime/io-stmt.cpp

Removed: 
    


################################################################################
diff  --git a/flang/runtime/io-stmt.cpp b/flang/runtime/io-stmt.cpp
index 3ab5c879fbb66..c7e349a46768f 100644
--- a/flang/runtime/io-stmt.cpp
+++ b/flang/runtime/io-stmt.cpp
@@ -186,7 +186,12 @@ ExternalIoStatementBase::ExternalIoStatementBase(
     ExternalFileUnit &unit, const char *sourceFile, int sourceLine)
     : IoStatementBase{sourceFile, sourceLine}, unit_{unit} {}
 
-MutableModes &ExternalIoStatementBase::mutableModes() { return unit_.modes; }
+MutableModes &ExternalIoStatementBase::mutableModes() {
+  if (const ChildIo * child{unit_.GetChildIo()}) {
+    return child->parent().mutableModes();
+  }
+  return unit_.modes;
+}
 
 ConnectionState &ExternalIoStatementBase::GetConnectionState() { return unit_; }
 
@@ -981,8 +986,8 @@ bool InquireUnitState::Inquire(
   case HashInquiryKeyword("BLANK"):
     str = !unit().IsConnected() || unit().isUnformatted.value_or(true)
         ? "UNDEFINED"
-        : unit().modes.editingFlags & blankZero ? "ZERO"
-                                                : "NULL";
+        : mutableModes().editingFlags & blankZero ? "ZERO"
+                                                  : "NULL";
     break;
   case HashInquiryKeyword("CARRIAGECONTROL"):
     str = "LIST";
@@ -993,14 +998,14 @@ bool InquireUnitState::Inquire(
   case HashInquiryKeyword("DECIMAL"):
     str = !unit().IsConnected() || unit().isUnformatted.value_or(true)
         ? "UNDEFINED"
-        : unit().modes.editingFlags & decimalComma ? "COMMA"
-                                                   : "POINT";
+        : mutableModes().editingFlags & decimalComma ? "COMMA"
+                                                     : "POINT";
     break;
   case HashInquiryKeyword("DELIM"):
     if (!unit().IsConnected() || unit().isUnformatted.value_or(true)) {
       str = "UNDEFINED";
     } else {
-      switch (unit().modes.delim) {
+      switch (mutableModes().delim) {
       case '\'':
         str = "APOSTROPHE";
         break;
@@ -1046,8 +1051,8 @@ bool InquireUnitState::Inquire(
   case HashInquiryKeyword("PAD"):
     str = !unit().IsConnected() || unit().isUnformatted.value_or(true)
         ? "UNDEFINED"
-        : unit().modes.pad ? "YES"
-                           : "NO";
+        : mutableModes().pad ? "YES"
+                             : "NO";
     break;
   case HashInquiryKeyword("POSITION"):
     if (!unit().IsConnected() || unit().access == Access::Direct) {
@@ -1078,7 +1083,7 @@ bool InquireUnitState::Inquire(
     if (!unit().IsConnected() || unit().isUnformatted.value_or(true)) {
       str = "UNDEFINED";
     } else {
-      switch (unit().modes.round) {
+      switch (mutableModes().round) {
       case decimal::FortranRounding::RoundNearest:
         str = "NEAREST";
         break;
@@ -1107,8 +1112,8 @@ bool InquireUnitState::Inquire(
   case HashInquiryKeyword("SIGN"):
     str = !unit().IsConnected() || unit().isUnformatted.value_or(true)
         ? "UNDEFINED"
-        : unit().modes.editingFlags & signPlus ? "PLUS"
-                                               : "SUPPRESS";
+        : mutableModes().editingFlags & signPlus ? "PLUS"
+                                                 : "SUPPRESS";
     break;
   case HashInquiryKeyword("STREAM"):
     str = !unit().IsConnected()           ? "UNKNOWN"


        


More information about the flang-commits mailing list