[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 https://github.com/llvm/llvm-project/issues/153416.
This commit is contained in:
Peter Klausler 2025-08-18 14:44:48 -07:00 committed by GitHub
parent ffec266980
commit 9a7a16c8d5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 3 deletions

View File

@ -696,6 +696,7 @@ public:
RT_API_ATTRS ChildListIoStatementState(
ChildIo &, const char *sourceFile = nullptr, int sourceLine = 0);
using ListDirectedStatementState<DIR>::GetNextDataEdit;
RT_API_ATTRS bool AdvanceRecord(int = 1);
RT_API_ATTRS int EndIoStatement();
};

View File

@ -1106,10 +1106,14 @@ ChildListIoStatementState<DIR>::ChildListIoStatementState(
}
template <Direction DIR>
bool ChildUnformattedIoStatementState<DIR>::Receive(
char *data, std::size_t bytes, std::size_t elementBytes) {
bool ChildListIoStatementState<DIR>::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
@ -1125,6 +1129,16 @@ template <Direction DIR> int ChildListIoStatementState<DIR>::EndIoStatement() {
return ChildIoStatementState<DIR>::EndIoStatement();
}
template <Direction DIR>
bool ChildUnformattedIoStatementState<DIR>::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<Direction::Output>;
template class InternalIoStatementState<Direction::Input>;
template class InternalFormattedIoStatementState<Direction::Output>;