[flang-commits] [PATCH] D132157: [flang][runtime] Catch input error on missing NAMELIST scalar
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Thu Aug 18 11:19:09 PDT 2022
klausler created this revision.
klausler added a reviewer: vdonaldson.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
klausler requested review of this revision.
While a NAMELIST input group item for an array can have fewer
values than expected, or none, an input group item for a scalar
must have a value.
https://reviews.llvm.org/D132157
Files:
flang/runtime/io-stmt.h
flang/runtime/namelist.cpp
Index: flang/runtime/namelist.cpp
===================================================================
--- flang/runtime/namelist.cpp
+++ flang/runtime/namelist.cpp
@@ -475,7 +475,7 @@
}
io.HandleRelativePosition(byteCount);
// Read the values into the descriptor. An array can be short.
- listInput->ResetForNextNamelistItem();
+ listInput->ResetForNextNamelistItem(useDescriptor->rank() > 0);
if (!descr::DescriptorIO<Direction::Input>(io, *useDescriptor)) {
return false;
}
@@ -494,8 +494,9 @@
}
bool IsNamelistName(IoStatementState &io) {
- if (io.get_if<ListDirectedStatementState<Direction::Input>>()) {
- if (io.mutableModes().inNamelist) {
+ if (auto *listInput{
+ io.get_if<ListDirectedStatementState<Direction::Input>>()}) {
+ if (listInput->inNamelistArray()) {
SavedPosition savedPosition{io};
std::size_t byteCount{0};
if (auto ch{io.GetNextNonBlank(byteCount)}) {
Index: flang/runtime/io-stmt.h
===================================================================
--- flang/runtime/io-stmt.h
+++ flang/runtime/io-stmt.h
@@ -293,6 +293,9 @@
class ListDirectedStatementState<Direction::Input>
: public FormattedIoStatementState<Direction::Input> {
public:
+ bool inNamelistArray() const { return inNamelistArray_; }
+ void set_inNamelistArray(bool yes = true) { inNamelistArray_ = yes; }
+
// Skips value separators, handles repetition and null values.
// Vacant when '/' appears; present with descriptor == ListDirectedNullValue
// when a null value appears.
@@ -303,10 +306,11 @@
// input statement. This member function resets some state so that
// repetition and null values work correctly for each successive
// NAMELIST input item.
- void ResetForNextNamelistItem() {
+ void ResetForNextNamelistItem(bool inNamelistArray) {
remaining_ = 0;
eatComma_ = false;
realPart_ = imaginaryPart_ = false;
+ inNamelistArray_ = inNamelistArray;
}
private:
@@ -316,6 +320,7 @@
bool hitSlash_{false}; // once '/' is seen, nullify further items
bool realPart_{false};
bool imaginaryPart_{false};
+ bool inNamelistArray_{false};
};
template <Direction DIR>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132157.453721.patch
Type: text/x-patch
Size: 2206 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220818/277f4ec9/attachment.bin>
More information about the flang-commits
mailing list