Skip to content

Commit 71389a5

Browse files
authored
[flang][runtime] Preserve some list-directed input state in child (#157571)
Child list-directed input needs to inherit and return the state used to process trailing separators (eatComma_) and terminal '/' (hitSlash_) from any parent list-directed input statement. Fixes #157509 and #154971.
1 parent 0a69cd4 commit 71389a5

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

flang-rt/include/flang-rt/runtime/io-stmt.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,11 @@ class ListDirectedStatementState<Direction::Input>
458458
namelistGroup_ = namelistGroup;
459459
}
460460

461+
RT_API_ATTRS bool eatComma() const { return eatComma_; }
462+
RT_API_ATTRS void set_eatComma(bool yes) { eatComma_ = yes; }
463+
RT_API_ATTRS bool hitSlash() const { return hitSlash_; }
464+
RT_API_ATTRS void set_hitSlash(bool yes) { hitSlash_ = yes; }
465+
461466
protected:
462467
const NamelistGroup *namelistGroup_{nullptr};
463468

flang-rt/lib/runtime/io-stmt.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,14 @@ void ChildFormattedIoStatementState<DIR, CHAR>::CompleteOperation() {
10761076

10771077
template <Direction DIR, typename CHAR>
10781078
int ChildFormattedIoStatementState<DIR, CHAR>::EndIoStatement() {
1079+
if constexpr (DIR == Direction::Input) {
1080+
if (auto *listInput{this->child()
1081+
.parent()
1082+
.template get_if<
1083+
ListDirectedStatementState<Direction::Input>>()}) {
1084+
listInput->set_eatComma(false);
1085+
}
1086+
}
10791087
CompleteOperation();
10801088
return ChildIoStatementState<DIR>::EndIoStatement();
10811089
}
@@ -1097,6 +1105,7 @@ ChildListIoStatementState<DIR>::ChildListIoStatementState(
10971105
if constexpr (DIR == Direction::Input) {
10981106
if (auto *listInput{child.parent()
10991107
.get_if<ListDirectedStatementState<Direction::Input>>()}) {
1108+
this->set_eatComma(listInput->eatComma());
11001109
this->namelistGroup_ = listInput->namelistGroup();
11011110
}
11021111
}
@@ -1121,6 +1130,13 @@ bool ChildListIoStatementState<DIR>::AdvanceRecord(int n) {
11211130

11221131
template <Direction DIR> int ChildListIoStatementState<DIR>::EndIoStatement() {
11231132
if constexpr (DIR == Direction::Input) {
1133+
if (auto *listInput{this->child()
1134+
.parent()
1135+
.template get_if<
1136+
ListDirectedStatementState<Direction::Input>>()}) {
1137+
listInput->set_eatComma(this->eatComma());
1138+
listInput->set_hitSlash(this->hitSlash());
1139+
}
11241140
if (int status{ListDirectedStatementState<DIR>::EndIoStatement()};
11251141
status != IostatOk) {
11261142
return status;

0 commit comments

Comments
 (0)