[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 10:57:13 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.

Internal writes to character arrays should not blank-fill
records (elements) past the last one that was written to.


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
@@ -22,6 +22,7 @@
     const std::string &expect, const std::string &&got) {
   std::string want{expect};
   want.resize(got.size(), ' ');
+  EXPECT_EQ(want, got) << "pmk: ";
   return want == got;
 }
 
@@ -118,6 +119,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 +139,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.400072.patch
Type: text/x-patch
Size: 3310 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220114/109e75c0/attachment-0001.bin>


More information about the flang-commits mailing list