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

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Wed Mar 2 11:18:00 PST 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.

Advancement to new output lines was taking fixed-sized direct-access
and internal character array element lengths into account, but not
RECL= settings from OPEN statements.


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.412492.patch
Type: text/x-patch
Size: 2546 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220302/b4426e48/attachment.bin>


More information about the flang-commits mailing list