-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Conversation
@llvm/pr-subscribers-flang-runtime Changes…ent list When a derived type value appears in NAMELIST input, its components' values appear in sequence. This sequence can be truncated by a NAME= that begins the next NAMELIST input item, or by the terminal '/' that ends the NAMELIST group. Extend the mechanism already in place for truncated array item lists in NAMELIST input so that it also applies to derived type component sequences, and rename things appropriately. Full diff: https://github.com/llvm/llvm-project/pull/66831.diff 2 Files Affected:
diff --git a/flang/runtime/io-stmt.h b/flang/runtime/io-stmt.h
index fa432d07a680deb..d4ceb83265246bd 100644
--- a/flang/runtime/io-stmt.h
+++ b/flang/runtime/io-stmt.h
@@ -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
@@ -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:
@@ -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>
diff --git a/flang/runtime/namelist.cpp b/flang/runtime/namelist.cpp
index 1b3207ef2f93212..61815a7cc8a4032 100644
--- a/flang/runtime/namelist.cpp
+++ b/flang/runtime/namelist.cpp
@@ -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) {
@@ -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)}) {
|
c287a32
to
5f7d702
Compare
…ent list When a derived type value appears in NAMELIST input, its components' values appear in sequence. This sequence can be truncated by a NAME= that begins the next NAMELIST input item, or by the terminal '/' that ends the NAMELIST group. Extend the mechanism already in place for truncated array item lists in NAMELIST input so that it also applies to derived type component sequences, and rename things appropriately.
…ent list
When a derived type value appears in NAMELIST input, its components' values appear in sequence. This sequence can be truncated by a NAME= that begins the next NAMELIST input item, or by the terminal '/' that ends the NAMELIST group. Extend the mechanism already in place for truncated array item lists in NAMELIST input so that it also applies to derived type component sequences, and rename things appropriately.