[flang-commits] [flang] 3a96446 - [flang] Honor RECL= in list-directed/namelist output

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


Author: Peter Klausler
Date: 2022-03-02T12:07:18-08:00
New Revision: 3a96446d51c0ae95a5ecb967976b14337c7cfe71

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

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

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.

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/flang/runtime/connection.cpp b/flang/runtime/connection.cpp
index 4172a8361857c..0abacd7995b47 100644
--- a/flang/runtime/connection.cpp
+++ b/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;
 }
 

diff  --git a/flang/runtime/edit-output.cpp b/flang/runtime/edit-output.cpp
index 079d8aefefad2..aa5ef489d22e7 100644
--- a/flang/runtime/edit-output.cpp
+++ b/flang/runtime/edit-output.cpp
@@ -477,13 +477,13 @@ bool ListDirectedDefaultCharacterOutput(IoStatementState &io,
     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 @@ bool ListDirectedDefaultCharacterOutput(IoStatementState &io,
     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())};

diff  --git a/flang/runtime/namelist.cpp b/flang/runtime/namelist.cpp
index 96bffa77b4d5a..762b885b56b3b 100644
--- a/flang/runtime/namelist.cpp
+++ b/flang/runtime/namelist.cpp
@@ -54,9 +54,13 @@ bool IONAME(OutputNamelist)(Cookie cookie, const NamelistGroup &group) {
   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))) {


        


More information about the flang-commits mailing list