[flang-commits] [flang] e093cbb - [flang] Runtime: Reset list-directed input state for each NAMELIST item

peter klausler via flang-commits flang-commits at lists.llvm.org
Fri Jul 23 18:21:43 PDT 2021


Author: peter klausler
Date: 2021-07-23T18:21:33-07:00
New Revision: e093cbb7ae1448379cad5520db5dfa5cf0b06bdf

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

LOG: [flang] Runtime: Reset list-directed input state for each NAMELIST item

NAMELIST I/O formatting uses the runtime infrastructure for
list-directed I/O.  List-directed input processing has same state
that requires reinitialization for each successive NAMELIST input
item.  This patch fixes bugs with "null" items and repetition counts
on NAMELIST input items after the first in the group.

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

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 49964359a48ba..eeae5105a13cd 100644
--- a/flang/runtime/io-stmt.h
+++ b/flang/runtime/io-stmt.h
@@ -217,6 +217,16 @@ class ListDirectedStatementState<Direction::Input>
   std::optional<DataEdit> GetNextDataEdit(
       IoStatementState &, int maxRepeat = 1);
 
+  // Each NAMELIST input item is a distinct "list-directed"
+  // input statement.  This member function resets this state
+  // so that repetition and null values work correctly for each
+  // successive NAMELIST input item.
+  void ResetForNextNamelistItem() {
+    remaining_ = 0;
+    isFirstItem_ = true;
+    realPart_ = imaginaryPart_ = false;
+  }
+
 private:
   int remaining_{0}; // for "r*" repetition
   std::int64_t initialRecordNumber_;

diff  --git a/flang/runtime/namelist.cpp b/flang/runtime/namelist.cpp
index 72d669f1b89b4..7ca8d5cfb1698 100644
--- a/flang/runtime/namelist.cpp
+++ b/flang/runtime/namelist.cpp
@@ -260,6 +260,8 @@ bool IONAME(InputNamelist)(Cookie cookie, const NamelistGroup &group) {
   ConnectionState &connection{io.GetConnectionState()};
   connection.modes.inNamelist = true;
   IoErrorHandler &handler{io.GetIoErrorHandler()};
+  auto *listInput{io.get_if<ListDirectedStatementState<Direction::Input>>()};
+  RUNTIME_CHECK(handler, listInput != nullptr);
   // Check the group header
   std::optional<char32_t> next{io.GetNextNonBlank()};
   if (!next || *next != '&') {
@@ -331,6 +333,7 @@ bool IONAME(InputNamelist)(Cookie cookie, const NamelistGroup &group) {
     }
     io.HandleRelativePosition(1);
     // Read the values into the descriptor
+    listInput->ResetForNextNamelistItem();
     if (!descr::DescriptorIO<Direction::Input>(io, *useDescriptor)) {
       return false;
     }


        


More information about the flang-commits mailing list