diff --git a/flang-rt/include/flang-rt/runtime/io-stmt.h b/flang-rt/include/flang-rt/runtime/io-stmt.h
index 9f71d515cb615..9d50f7c10c4f6 100644
--- a/flang-rt/include/flang-rt/runtime/io-stmt.h
+++ b/flang-rt/include/flang-rt/runtime/io-stmt.h
@@ -696,6 +696,7 @@ class ChildListIoStatementState : public ChildIoStatementState
,
RT_API_ATTRS ChildListIoStatementState(
ChildIo &, const char *sourceFile = nullptr, int sourceLine = 0);
using ListDirectedStatementState::GetNextDataEdit;
+ RT_API_ATTRS bool AdvanceRecord(int = 1);
RT_API_ATTRS int EndIoStatement();
};
diff --git a/flang-rt/lib/runtime/io-stmt.cpp b/flang-rt/lib/runtime/io-stmt.cpp
index e08088fab4311..9b1e696b3f12f 100644
--- a/flang-rt/lib/runtime/io-stmt.cpp
+++ b/flang-rt/lib/runtime/io-stmt.cpp
@@ -1095,10 +1095,14 @@ ChildListIoStatementState::ChildListIoStatementState(
}
template
-bool ChildUnformattedIoStatementState::Receive(
- char *data, std::size_t bytes, std::size_t elementBytes) {
+bool ChildListIoStatementState::AdvanceRecord(int n) {
#if !defined(RT_DEVICE_AVOID_RECURSION)
- return this->child().parent().Receive(data, bytes, elementBytes);
+ // Allow child NAMELIST input to advance
+ if (DIR == Direction::Input && this->mutableModes().inNamelist) {
+ return this->child().parent().AdvanceRecord(n);
+ } else {
+ return false;
+ }
#else
this->ReportUnsupportedChildIo();
#endif
@@ -1114,6 +1118,16 @@ template int ChildListIoStatementState::EndIoStatement() {
return ChildIoStatementState::EndIoStatement();
}
+template
+bool ChildUnformattedIoStatementState::Receive(
+ char *data, std::size_t bytes, std::size_t elementBytes) {
+#if !defined(RT_DEVICE_AVOID_RECURSION)
+ return this->child().parent().Receive(data, bytes, elementBytes);
+#else
+ this->ReportUnsupportedChildIo();
+#endif
+}
+
template class InternalIoStatementState;
template class InternalIoStatementState;
template class InternalFormattedIoStatementState;