[flang-commits] [PATCH] D117342: [flang] Don't blank-fill remaining lines in internal output

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Fri Jan 14 15:15:04 PST 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rGb77fd01a8f44: [flang] Don't blank-fill remaining lines in internal 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/D117342/new/

https://reviews.llvm.org/D117342

Files:
  flang/runtime/internal-unit.cpp
  flang/runtime/internal-unit.h
  flang/unittests/Runtime/NumericalFormatTest.cpp


Index: flang/unittests/Runtime/NumericalFormatTest.cpp
===================================================================
--- flang/unittests/Runtime/NumericalFormatTest.cpp
+++ flang/unittests/Runtime/NumericalFormatTest.cpp
@@ -118,6 +118,9 @@
   auto cookie{IONAME(BeginInternalArrayFormattedOutput)(
       section, format, std::strlen(format))};
 
+  // Fill last line with periods
+  std::memset(buffer[numLines - 1], '.', lineLength);
+
   // Write data to buffer
   IONAME(OutputAscii)(cookie, "WORLD", 5);
   IONAME(OutputAscii)(cookie, "HELLO", 5);
@@ -135,7 +138,7 @@
                                   "                                "
                                   "789                 abcd 666 777"
                                   " 888 999                        "
-                                  "                                "};
+                                  "................................"};
   // Ensure formatted string matches expected output
   EXPECT_TRUE(
       CompareFormattedStrings(expect, std::string{buffer[0], sizeof buffer}))
Index: flang/runtime/internal-unit.h
===================================================================
--- flang/runtime/internal-unit.h
+++ flang/runtime/internal-unit.h
@@ -45,6 +45,8 @@
     return descriptor().template ZeroBasedIndexedElement<char>(
         currentRecordNumber - 1);
   }
+  void BlankFillOutputRecord();
+
   StaticDescriptor<maxRank, true /*addendum*/> staticDescriptor_;
 };
 
Index: flang/runtime/internal-unit.cpp
===================================================================
--- flang/runtime/internal-unit.cpp
+++ flang/runtime/internal-unit.cpp
@@ -38,15 +38,9 @@
 }
 
 template <Direction DIR> void InternalDescriptorUnit<DIR>::EndIoStatement() {
-  if constexpr (DIR == Direction::Output) { // blank fill
-    while (char *record{CurrentRecord()}) {
-      if (furthestPositionInRecord <
-          recordLength.value_or(furthestPositionInRecord)) {
-        std::fill_n(record + furthestPositionInRecord,
-            *recordLength - furthestPositionInRecord, ' ');
-      }
-      furthestPositionInRecord = 0;
-      ++currentRecordNumber;
+  if constexpr (DIR == Direction::Output) {
+    if (furthestPositionInRecord > 0) {
+      BlankFillOutputRecord();
     }
   }
 }
@@ -127,18 +121,24 @@
     handler.SignalEnd();
     return false;
   }
-  if constexpr (DIR == Direction::Output) { // blank fill
+  if constexpr (DIR == Direction::Output) {
+    BlankFillOutputRecord();
+  }
+  ++currentRecordNumber;
+  BeginRecord();
+  return true;
+}
+
+template <Direction DIR>
+void InternalDescriptorUnit<DIR>::BlankFillOutputRecord() {
+  if constexpr (DIR == Direction::Output) {
     if (furthestPositionInRecord <
         recordLength.value_or(furthestPositionInRecord)) {
       char *record{CurrentRecord()};
-      RUNTIME_CHECK(handler, record != nullptr);
       std::fill_n(record + furthestPositionInRecord,
           *recordLength - furthestPositionInRecord, ' ');
     }
   }
-  ++currentRecordNumber;
-  BeginRecord();
-  return true;
 }
 
 template <Direction DIR>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117342.400166.patch
Type: text/x-patch
Size: 3107 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220114/24746707/attachment.bin>


More information about the flang-commits mailing list