Skip to content

Commit 1baf7db

Browse files
authored
[flang][runtime] Allow some list-directed child output to advance (llvm#166847)
List-directed child input is allowed to advance to new records in some circumstances, and list-directed output should be as well so that e.g. NAMELIST output via a defined WRITE(FORMATTED) generic doesn't get truncated by FORT_FMT_RECL. Fixes llvm#166804.
1 parent 3d0ae1e commit 1baf7db

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,8 +730,7 @@ class ChildListIoStatementState : public ChildIoStatementState<DIR>,
730730
RT_API_ATTRS bool AdvanceRecord(int = 1);
731731
RT_API_ATTRS int EndIoStatement();
732732
RT_API_ATTRS bool CanAdvance() {
733-
return DIR == Direction::Input &&
734-
(canAdvance_ || this->mutableModes().inNamelist);
733+
return canAdvance_ || this->mutableModes().inNamelist;
735734
}
736735

737736
private:

flang-rt/lib/runtime/edit-output.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,10 @@ bool RT_API_ATTRS EditIntegerOutput(IoStatementState &io, const DataEdit &edit,
175175
}
176176
if (edit.IsListDirected()) {
177177
int total{std::max(leadingSpaces, 1) + subTotal};
178-
if (io.GetConnectionState().NeedAdvance(static_cast<std::size_t>(total)) &&
179-
!io.AdvanceRecord()) {
180-
return false;
178+
if (io.GetConnectionState().NeedAdvance(static_cast<std::size_t>(total))) {
179+
if (!io.AdvanceRecord()) {
180+
return false;
181+
}
181182
}
182183
leadingSpaces = 1;
183184
} else if (!edit.width) {

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,20 +1109,20 @@ ChildListIoStatementState<DIR>::ChildListIoStatementState(
11091109
ChildIo &child, const char *sourceFile, int sourceLine)
11101110
: ChildIoStatementState<DIR>{child, sourceFile, sourceLine} {
11111111
#if !defined(RT_DEVICE_AVOID_RECURSION)
1112-
if constexpr (DIR == Direction::Input) {
1113-
if (const auto *listInput{child.parent()
1114-
.get_if<ListDirectedStatementState<Direction::Input>>()}) {
1115-
this->set_eatComma(listInput->eatComma());
1116-
this->namelistGroup_ = listInput->namelistGroup();
1117-
if (auto *childListInput{child.parent()
1118-
.get_if<ChildListIoStatementState<Direction::Input>>()}) {
1119-
// Child list input whose parent is child list input: can advance
1120-
// if the parent can.
1121-
this->canAdvance_ = childListInput->CanAdvance();
1122-
} else {
1123-
// Child list input of top-level list input: can advance.
1124-
this->canAdvance_ = true;
1125-
}
1112+
if (const auto *listParent{
1113+
child.parent().get_if<ListDirectedStatementState<DIR>>()}) {
1114+
if constexpr (DIR == Direction::Input) {
1115+
this->set_eatComma(listParent->eatComma());
1116+
this->namelistGroup_ = listParent->namelistGroup();
1117+
}
1118+
if (auto *childListParent{
1119+
child.parent().get_if<ChildListIoStatementState<DIR>>()}) {
1120+
// Child list I/O whose parent is child list I/O: can advance
1121+
// if the parent can.
1122+
this->canAdvance_ = childListParent->CanAdvance();
1123+
} else {
1124+
// Child list I/O of top-level list I/O: can advance.
1125+
this->canAdvance_ = true;
11261126
}
11271127
}
11281128
#else

0 commit comments

Comments
 (0)