[PATCH] D120837: [flang] Honor RECL= in list-directed/namelist output

Peter Klausler via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 2 12:07:37 PST 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG3a96446d51c0: [flang] Honor RECL= in list-directed/namelist output (authored by klausler).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120837/new/

https://reviews.llvm.org/D120837

Files:
  flang/runtime/connection.cpp
  flang/runtime/edit-output.cpp
  flang/runtime/namelist.cpp


Index: flang/runtime/namelist.cpp
===================================================================
--- flang/runtime/namelist.cpp
+++ flang/runtime/namelist.cpp
@@ -54,9 +54,13 @@
   if (!(EmitWithAdvance('&') && EmitUpperCase(group.groupName))) {
     return false;
   }
+  auto *listOutput{io.get_if<ListDirectedStatementState<Direction::Output>>()};
   for (std::size_t j{0}; j < group.items; ++j) {
     // [,]ITEM=...
     const NamelistGroup::Item &item{group.item[j]};
+    if (listOutput) {
+      listOutput->set_lastWasUndelimitedCharacter(false);
+    }
     if (!(EmitWithAdvance(j == 0 ? ' ' : comma) && EmitUpperCase(item.name) &&
             EmitWithAdvance('=') &&
             descr::DescriptorIO<Direction::Output>(io, item.descriptor))) {
Index: flang/runtime/edit-output.cpp
===================================================================
--- flang/runtime/edit-output.cpp
+++ flang/runtime/edit-output.cpp
@@ -477,13 +477,13 @@
     ok = ok && list.EmitLeadingSpaceOrAdvance(io);
     // Value is delimited with ' or " marks, and interior
     // instances of that character are doubled.
-    ok = ok && io.Emit(&modes.delim, 1);
     auto EmitOne{[&](char ch) {
       if (connection.NeedAdvance(1)) {
         ok = ok && io.AdvanceRecord();
       }
       ok = ok && io.Emit(&ch, 1);
     }};
+    EmitOne(modes.delim);
     for (std::size_t j{0}; j < length; ++j) {
       // Doubled delimiters must be put on the same record
       // in order to be acceptable as list-directed or NAMELIST
@@ -502,9 +502,7 @@
     EmitOne(modes.delim);
   } else {
     // Undelimited list-directed output
-    ok = ok &&
-        list.EmitLeadingSpaceOrAdvance(
-            io, length > 0 && !list.lastWasUndelimitedCharacter());
+    ok = ok && list.EmitLeadingSpaceOrAdvance(io, length > 0 ? 1 : 0, true);
     std::size_t put{0};
     while (ok && put < length) {
       auto chunk{std::min(length - put, connection.RemainingSpaceInRecord())};
Index: flang/runtime/connection.cpp
===================================================================
--- flang/runtime/connection.cpp
+++ flang/runtime/connection.cpp
@@ -14,8 +14,8 @@
 namespace Fortran::runtime::io {
 
 std::size_t ConnectionState::RemainingSpaceInRecord() const {
-  auto recl{recordLength.value_or(
-      executionEnvironment.listDirectedOutputLineLengthLimit)};
+  auto recl{recordLength.value_or(openRecl.value_or(
+      executionEnvironment.listDirectedOutputLineLengthLimit))};
   return positionInRecord >= recl ? 0 : recl - positionInRecord;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120837.412503.patch
Type: text/x-patch
Size: 2546 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220302/3abe2817/attachment.bin>


More information about the llvm-commits mailing list