[flang-commits] [flang] [flang][runtime] Terminate last partial record after non-advancing write (PR #74524)
via flang-commits
flang-commits at lists.llvm.org
Tue Dec 5 13:14:19 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-runtime
Author: Peter Klausler (klausler)
<details>
<summary>Changes</summary>
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
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;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/74524
More information about the flang-commits
mailing list