Skip to content

[flang][runtime] Terminate last partial record after non-advancing write #74524

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

After a non-advancing WRITE to a unit, ensure that any ENDFILE operation (explicit or implicit) terminates the record. (All other Fortran implementations do so except XLF.)

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

@klausler klausler requested a review from vdonaldson December 5, 2023 21:13
@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

After a non-advancing WRITE to a unit, ensure that any ENDFILE operation (explicit or implicit) terminates the record. (All other Fortran implementations do so except XLF.)

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


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

1 Files Affected:

  • (modified) flang/runtime/unit.cpp (+2-7)
diff --git a/flang/runtime/unit.cpp b/flang/runtime/unit.cpp
index 995656b9480c4..3895eb5c40894 100644
--- a/flang/runtime/unit.cpp
+++ b/flang/runtime/unit.cpp
@@ -591,9 +591,6 @@ void ExternalFileUnit::BackspaceRecord(IoErrorHandler &handler) {
     if (IsAfterEndfile()) {
       // BACKSPACE after explicit ENDFILE
       currentRecordNumber = *endfileRecordNumber;
-    } else if (leftTabLimit) {
-      // BACKSPACE after non-advancing I/O
-      leftTabLimit.reset();
     } else {
       DoImpliedEndfile(handler);
       if (frameOffsetInFile_ + recordOffsetInFrame_ > 0) {
@@ -910,10 +907,8 @@ void ExternalFileUnit::DoEndfile(IoErrorHandler &handler) {
   if (IsRecordFile() && access != Access::Direct) {
     furthestPositionInRecord =
         std::max(positionInRecord, furthestPositionInRecord);
-    if (leftTabLimit) {
-      // Last read/write was non-advancing, so AdvanceRecord() was not called.
-      leftTabLimit.reset();
-      ++currentRecordNumber;
+    if (direction_ == Direction::Output && leftTabLimit) {
+      AdvanceRecord(handler); // last write was non-advancing
     }
     endfileRecordNumber = currentRecordNumber;
   }

@klausler klausler force-pushed the advance branch 7 times, most recently from 09db51b to 42aa48d Compare December 9, 2023 17:48
After a non-advancing WRITE to a unit, ensure that any ENDFILE
operation (explicit or implicit) flushes and, if not stream output,
terminates the record.  (All other Fortran implementations do so
except XLF.)

Fixes llvm-test-suite/Fortran/gfortran/regression/advance_6.f90.
@klausler klausler merged commit b626053 into llvm:main Dec 11, 2023
@klausler klausler deleted the advance branch December 11, 2023 20:25
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