Skip to content

Commit

Permalink
[flang][runtime] Return the right mutable modes from INQUIRE in child…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
klausler committed Feb 15, 2023
1 parent 6dd9d18 commit ef15617
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions flang/runtime/io-stmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_; }

Expand Down Expand Up @@ -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";
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit ef15617

Please sign in to comment.