[flang-commits] [PATCH] D118745: [flang] Set right "inNamelist" flag

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Tue Feb 1 16:58:24 PST 2022


klausler created this revision.
klausler added a reviewer: vdonaldson.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
klausler requested review of this revision.

NAMELIST I/O was inconsistent in its choice of which set of I/O modes
to set the "inNamelist" flag.  The wrong choice was in the set of modes
that are part of the persistent state of an I/O connection; the right
place is the set of modes that are reinitialized at the beginning of
each I/O statement so that they can be modified by READ/WRITE control
list specifiers and FORMAT control edit descriptors.  Fix.


https://reviews.llvm.org/D118745

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


Index: flang/runtime/namelist.cpp
===================================================================
--- flang/runtime/namelist.cpp
+++ flang/runtime/namelist.cpp
@@ -28,9 +28,9 @@
 bool IONAME(OutputNamelist)(Cookie cookie, const NamelistGroup &group) {
   IoStatementState &io{*cookie};
   io.CheckFormattedStmtType<Direction::Output>("OutputNamelist");
-  ConnectionState &connection{io.GetConnectionState()};
-  connection.modes.inNamelist = true;
+  io.mutableModes().inNamelist = true;
   char comma{static_cast<char>(GetComma(io))};
+  ConnectionState &connection{io.GetConnectionState()};
   // Internal functions to advance records and convert case
   const auto EmitWithAdvance{[&](char ch) -> bool {
     return (!connection.NeedAdvance(1) || io.AdvanceRecord()) &&
@@ -355,8 +355,7 @@
 bool IONAME(InputNamelist)(Cookie cookie, const NamelistGroup &group) {
   IoStatementState &io{*cookie};
   io.CheckFormattedStmtType<Direction::Input>("InputNamelist");
-  ConnectionState &connection{io.GetConnectionState()};
-  connection.modes.inNamelist = true;
+  io.mutableModes().inNamelist = true;
   IoErrorHandler &handler{io.GetIoErrorHandler()};
   auto *listInput{io.get_if<ListDirectedStatementState<Direction::Input>>()};
   RUNTIME_CHECK(handler, listInput != nullptr);
@@ -485,8 +484,7 @@
 
 bool IsNamelistName(IoStatementState &io) {
   if (io.get_if<ListDirectedStatementState<Direction::Input>>()) {
-    ConnectionState &connection{io.GetConnectionState()};
-    if (connection.modes.inNamelist) {
+    if (io.mutableModes().inNamelist) {
       SavedPosition savedPosition{io};
       if (auto ch{io.GetNextNonBlank()}) {
         if (IsLegalIdStart(*ch)) {
Index: flang/runtime/io-stmt.h
===================================================================
--- flang/runtime/io-stmt.h
+++ flang/runtime/io-stmt.h
@@ -220,7 +220,7 @@
   // Skips spaces, advances records, and ignores NAMELIST comments
   std::optional<char32_t> GetNextNonBlank() {
     auto ch{GetCurrentChar()};
-    bool inNamelist{GetConnectionState().modes.inNamelist};
+    bool inNamelist{mutableModes().inNamelist};
     while (!ch || *ch == ' ' || *ch == '\t' || (inNamelist && *ch == '!')) {
       if (ch && (*ch == ' ' || *ch == '\t')) {
         HandleRelativePosition(1);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118745.405124.patch
Type: text/x-patch
Size: 2275 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220202/06c61ca6/attachment-0001.bin>


More information about the flang-commits mailing list