Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flang][runtime] Handle incomplete NAMELIST input derived type compon… #66831

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion flang/runtime/descriptor-io.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,11 @@ static bool DefaultComponentwiseIO(IoStatementState &io,
*compArray.Element<typeInfo::Component>(at)};
if (!DefaultComponentIO<DIR>(
io, component, descriptor, subscripts, handler, table)) {
return false;
// Truncated nonempty namelist input sequence?
auto *listInput{
io.get_if<ListDirectedStatementState<Direction::Input>>()};
return DIR == Direction::Input && (j > 0 || k > 0) && listInput &&
listInput->inNamelistSequence();
}
}
}
Expand Down
9 changes: 4 additions & 5 deletions flang/runtime/io-stmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,7 @@ template <>
class ListDirectedStatementState<Direction::Input>
: public FormattedIoStatementState<Direction::Input> {
public:
bool inNamelistArray() const { return inNamelistArray_; }
void set_inNamelistArray(bool yes = true) { inNamelistArray_ = yes; }
bool inNamelistSequence() const { return inNamelistSequence_; }

// Skips value separators, handles repetition and null values.
// Vacant when '/' appears; present with descriptor == ListDirectedNullValue
Expand All @@ -308,11 +307,11 @@ class ListDirectedStatementState<Direction::Input>
// input statement. This member function resets some state so that
// repetition and null values work correctly for each successive
// NAMELIST input item.
void ResetForNextNamelistItem(bool inNamelistArray) {
void ResetForNextNamelistItem(bool inNamelistSequence) {
remaining_ = 0;
eatComma_ = false;
realPart_ = imaginaryPart_ = false;
inNamelistArray_ = inNamelistArray;
inNamelistSequence_ = inNamelistSequence;
}

private:
Expand All @@ -322,7 +321,7 @@ class ListDirectedStatementState<Direction::Input>
bool hitSlash_{false}; // once '/' is seen, nullify further items
bool realPart_{false};
bool imaginaryPart_{false};
bool inNamelistArray_{false};
bool inNamelistSequence_{false};
};

template <Direction DIR>
Expand Down
11 changes: 7 additions & 4 deletions flang/runtime/namelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,15 +522,18 @@ bool IONAME(InputNamelist)(Cookie cookie, const NamelistGroup &group) {
}
io.HandleRelativePosition(byteCount);
// Read the values into the descriptor. An array can be short.
listInput->ResetForNextNamelistItem(useDescriptor->rank() > 0);
if (const auto *addendum{useDescriptor->Addendum()};
addendum && addendum->derivedType()) {
const NonTbpDefinedIoTable *table{group.nonTbpDefinedIo};
listInput->ResetForNextNamelistItem(/*inNamelistSequence=*/true);
if (!IONAME(InputDerivedType)(cookie, *useDescriptor, table)) {
return false;
}
} else if (!descr::DescriptorIO<Direction::Input>(io, *useDescriptor)) {
return false;
} else {
listInput->ResetForNextNamelistItem(useDescriptor->rank() > 0);
if (!descr::DescriptorIO<Direction::Input>(io, *useDescriptor)) {
return false;
}
}
next = io.GetNextNonBlank(byteCount);
if (next && *next == comma) {
Expand All @@ -549,7 +552,7 @@ bool IONAME(InputNamelist)(Cookie cookie, const NamelistGroup &group) {
bool IsNamelistNameOrSlash(IoStatementState &io) {
if (auto *listInput{
io.get_if<ListDirectedStatementState<Direction::Input>>()}) {
if (listInput->inNamelistArray()) {
if (listInput->inNamelistSequence()) {
SavedPosition savedPosition{io};
std::size_t byteCount{0};
if (auto ch{io.GetNextNonBlank(byteCount)}) {
Expand Down