Skip to content

[flang][runtime] Clear last record in internal WRITE even if nothing … #74528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 11, 2023

Conversation

klausler
Copy link
Contributor

@klausler klausler commented Dec 5, 2023

…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.

…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.
@klausler klausler requested a review from vdonaldson December 5, 2023 21:49
@llvmbot llvmbot added flang:runtime flang Flang issues not falling into any other category labels Dec 5, 2023
@llvmbot
Copy link
Member

llvmbot commented Dec 5, 2023

@llvm/pr-subscribers-flang-runtime

Author: Peter Klausler (klausler)

Changes

…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.


Full diff: https://github.com/llvm/llvm-project/pull/74528.diff

1 Files Affected:

  • (modified) flang/runtime/internal-unit.cpp (+2-4)
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();
     }
   }

@klausler klausler merged commit 06b3144 into llvm:main Dec 11, 2023
@klausler klausler deleted the arrayio1 branch December 11, 2023 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:runtime flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants