Skip to content

Commit 76946cd

Browse files
committed
[flang][runtime] Allow child NAMELIST input to advance records
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 e315455 commit 76946cd

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
@@ -1095,10 +1095,14 @@ ChildListIoStatementState<DIR>::ChildListIoStatementState(
10951095
}
10961096

10971097
template <Direction DIR>
1098-
bool ChildUnformattedIoStatementState<DIR>::Receive(
1099-
char *data, std::size_t bytes, std::size_t elementBytes) {
1098+
bool ChildListIoStatementState<DIR>::AdvanceRecord(int n) {
11001099
#if !defined(RT_DEVICE_AVOID_RECURSION)
1101-
return this->child().parent().Receive(data, bytes, elementBytes);
1100+
// Allow child NAMELIST input to advance
1101+
if (DIR == Direction::Input && this->mutableModes().inNamelist) {
1102+
return this->child().parent().AdvanceRecord(n);
1103+
} else {
1104+
return false;
1105+
}
11021106
#else
11031107
this->ReportUnsupportedChildIo();
11041108
#endif
@@ -1114,6 +1118,16 @@ template <Direction DIR> int ChildListIoStatementState<DIR>::EndIoStatement() {
11141118
return ChildIoStatementState<DIR>::EndIoStatement();
11151119
}
11161120

1121+
template <Direction DIR>
1122+
bool ChildUnformattedIoStatementState<DIR>::Receive(
1123+
char *data, std::size_t bytes, std::size_t elementBytes) {
1124+
#if !defined(RT_DEVICE_AVOID_RECURSION)
1125+
return this->child().parent().Receive(data, bytes, elementBytes);
1126+
#else
1127+
this->ReportUnsupportedChildIo();
1128+
#endif
1129+
}
1130+
11171131
template class InternalIoStatementState<Direction::Output>;
11181132
template class InternalIoStatementState<Direction::Input>;
11191133
template class InternalFormattedIoStatementState<Direction::Output>;

0 commit comments

Comments
 (0)