[flang-commits] [flang] 2c39975 - [flang][runtime] Catch input error on missing NAMELIST scalar

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Thu Aug 18 14:37:17 PDT 2022


Author: Peter Klausler
Date: 2022-08-18T14:32:39-07:00
New Revision: 2c39975d99dfc6659986c1c5853a328afc25e139

URL: https://github.com/llvm/llvm-project/commit/2c39975d99dfc6659986c1c5853a328afc25e139
DIFF: https://github.com/llvm/llvm-project/commit/2c39975d99dfc6659986c1c5853a328afc25e139.diff

LOG: [flang][runtime] Catch input error on missing NAMELIST scalar

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.

Differential Revision: https://reviews.llvm.org/D132157

Added: 
    

Modified: 
    flang/runtime/io-stmt.h
    flang/runtime/namelist.cpp

Removed: 
    


################################################################################
diff  --git a/flang/runtime/io-stmt.h b/flang/runtime/io-stmt.h
index a4f9d633d288..0482a13d47f7 100644
--- a/flang/runtime/io-stmt.h
+++ b/flang/runtime/io-stmt.h
@@ -293,6 +293,9 @@ template <>
 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 @@ 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() {
+  void ResetForNextNamelistItem(bool inNamelistArray) {
     remaining_ = 0;
     eatComma_ = false;
     realPart_ = imaginaryPart_ = false;
+    inNamelistArray_ = inNamelistArray;
   }
 
 private:
@@ -316,6 +320,7 @@ class ListDirectedStatementState<Direction::Input>
   bool hitSlash_{false}; // once '/' is seen, nullify further items
   bool realPart_{false};
   bool imaginaryPart_{false};
+  bool inNamelistArray_{false};
 };
 
 template <Direction DIR>

diff  --git a/flang/runtime/namelist.cpp b/flang/runtime/namelist.cpp
index c206c029086c..2257fa5f487d 100644
--- a/flang/runtime/namelist.cpp
+++ b/flang/runtime/namelist.cpp
@@ -475,7 +475,7 @@ bool IONAME(InputNamelist)(Cookie cookie, const NamelistGroup &group) {
     }
     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 IONAME(InputNamelist)(Cookie cookie, const NamelistGroup &group) {
 }
 
 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)}) {


        


More information about the flang-commits mailing list