[flang-commits] [flang] [flang][runtime] Clear last record in internal WRITE even if nothing … (PR #74528)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Tue Dec 5 13:49:25 PST 2023


https://github.com/klausler created https://github.com/llvm/llvm-project/pull/74528

…was written

At the end of an internal output statement, The I/O runtime fills (the remainder of) the current record with blanks if it's the only record or if anything had been written to it.  This turns out to be wrong in the case of a format that ends with an explicit advance to the next record, which needs to be cleared even if nothing has been written.

Fixes llvm-test-suite/Fortran/gfortran/regression/arrayio_1.f90.

>From 0a3d496f0e247a4391ed38d87949f832660a76f4 Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Tue, 5 Dec 2023 13:42:19 -0800
Subject: [PATCH] [flang][runtime] Clear last record in internal WRITE even if
 nothing was written

At the end of an internal output statement, The I/O runtime fills
(the remainder of) the current record with blanks if it's the only
record or if anything had been written to it.  This turns out to be
wrong in the case of a format that ends with an explicit advance
to the next record, which needs to be cleared even if nothing
has been written.

Fixes llvm-test-suite/Fortran/gfortran/regression/arrayio_1.f90.
---
 flang/runtime/internal-unit.cpp | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/flang/runtime/internal-unit.cpp b/flang/runtime/internal-unit.cpp
index aa7130f3a6a53..e3fffaa6f378f 100644
--- a/flang/runtime/internal-unit.cpp
+++ b/flang/runtime/internal-unit.cpp
@@ -43,11 +43,9 @@ InternalDescriptorUnit<DIR>::InternalDescriptorUnit(
 
 template <Direction DIR> void InternalDescriptorUnit<DIR>::EndIoStatement() {
   if constexpr (DIR == Direction::Output) {
-    // Clear the remainder of the current record if anything was written
-    // to it, or if it is the only record.
+    // Clear the remainder of the current record.
     auto end{endfileRecordNumber.value_or(0)};
-    if (currentRecordNumber < end &&
-        (end == 2 || furthestPositionInRecord > 0)) {
+    if (currentRecordNumber < end) {
       BlankFillOutputRecord();
     }
   }



More information about the flang-commits mailing list