Skip to content

Commit 9a7a16c

Browse files
authored
[flang][runtime] Allow child NAMELIST input to advance records (#153963)
NAMELIST input in child I/O is rare, and it's not clear in the standard whether it should be allowed to advance to later records in the parent unit. But GNU Fortran supports it, and there's no good reason not to do so since a NAMELIST input group that isn't terminated on the same line is otherwise going to be a fatal error. Fixes #153416.
1 parent ffec266 commit 9a7a16c

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,7 @@ class ChildListIoStatementState : public ChildIoStatementState<DIR>,
696696
RT_API_ATTRS ChildListIoStatementState(
697697
ChildIo &, const char *sourceFile = nullptr, int sourceLine = 0);
698698
using ListDirectedStatementState<DIR>::GetNextDataEdit;
699+
RT_API_ATTRS bool AdvanceRecord(int = 1);
699700
RT_API_ATTRS int EndIoStatement();
700701
};
701702

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,10 +1106,14 @@ ChildListIoStatementState<DIR>::ChildListIoStatementState(
11061106
}
11071107

11081108
template <Direction DIR>
1109-
bool ChildUnformattedIoStatementState<DIR>::Receive(
1110-
char *data, std::size_t bytes, std::size_t elementBytes) {
1109+
bool ChildListIoStatementState<DIR>::AdvanceRecord(int n) {
11111110
#if !defined(RT_DEVICE_AVOID_RECURSION)
1112-
return this->child().parent().Receive(data, bytes, elementBytes);
1111+
// Allow child NAMELIST input to advance
1112+
if (DIR == Direction::Input && this->mutableModes().inNamelist) {
1113+
return this->child().parent().AdvanceRecord(n);
1114+
} else {
1115+
return false;
1116+
}
11131117
#else
11141118
this->ReportUnsupportedChildIo();
11151119
#endif
@@ -1125,6 +1129,16 @@ template <Direction DIR> int ChildListIoStatementState<DIR>::EndIoStatement() {
11251129
return ChildIoStatementState<DIR>::EndIoStatement();
11261130
}
11271131

1132+
template <Direction DIR>
1133+
bool ChildUnformattedIoStatementState<DIR>::Receive(
1134+
char *data, std::size_t bytes, std::size_t elementBytes) {
1135+
#if !defined(RT_DEVICE_AVOID_RECURSION)
1136+
return this->child().parent().Receive(data, bytes, elementBytes);
1137+
#else
1138+
this->ReportUnsupportedChildIo();
1139+
#endif
1140+
}
1141+
11281142
template class InternalIoStatementState<Direction::Output>;
11291143
template class InternalIoStatementState<Direction::Input>;
11301144
template class InternalFormattedIoStatementState<Direction::Output>;

0 commit comments

Comments
 (0)