[flang-commits] [flang] 8527f9e - [flang][runtime] Handle BACKSPACE after reading past EOF
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Tue May 24 10:28:04 PDT 2022
Author: Peter Klausler
Date: 2022-05-24T10:27:50-07:00
New Revision: 8527f9e4437fbecb529babb674777eb2cab99ca5
URL: https://github.com/llvm/llvm-project/commit/8527f9e4437fbecb529babb674777eb2cab99ca5
DIFF: https://github.com/llvm/llvm-project/commit/8527f9e4437fbecb529babb674777eb2cab99ca5.diff
LOG: [flang][runtime] Handle BACKSPACE after reading past EOF
An external READ(END=) that hits the end of the file must
also note the virtual position of the endfile record that
has just been discovered, so that a later BACKSPACE statement
won't end up at the wrong record.
Differential Revision: https://reviews.llvm.org/D126146
Added:
Modified:
flang/runtime/unit.cpp
flang/runtime/unit.h
Removed:
################################################################################
diff --git a/flang/runtime/unit.cpp b/flang/runtime/unit.cpp
index 7b4a0ea27bf92..c2f9d37bb1224 100644
--- a/flang/runtime/unit.cpp
+++ b/flang/runtime/unit.cpp
@@ -348,10 +348,7 @@ bool ExternalFileUnit::Receive(char *data, std::size_t bytes,
furthestPositionInRecord = furthestAfter;
return true;
} else {
- handler.SignalEnd();
- if (IsRecordFile() && access != Access::Direct) {
- endfileRecordNumber = currentRecordNumber;
- }
+ HitEndOnRead(handler);
return false;
}
}
@@ -384,10 +381,7 @@ const char *ExternalFileUnit::FrameNextInput(
if (got >= need) {
return Frame() + at;
}
- handler.SignalEnd();
- if (IsRecordFile() && access != Access::Direct) {
- endfileRecordNumber = currentRecordNumber;
- }
+ HitEndOnRead(handler);
}
return nullptr;
}
@@ -422,7 +416,7 @@ bool ExternalFileUnit::BeginReadingRecord(IoErrorHandler &handler) {
recordLength = openRecl;
} else {
recordLength.reset();
- handler.SignalEnd();
+ HitEndOnRead(handler);
}
} else {
recordLength.reset();
@@ -667,7 +661,7 @@ void ExternalFileUnit::BeginSequentialVariableUnformattedInputRecord(
const char *error{nullptr};
if (got < need) {
if (got == recordOffsetInFrame_) {
- handler.SignalEnd();
+ HitEndOnRead(handler);
} else {
error = "Unformatted variable-length sequential file input failed at "
"record #%jd (file offset %jd): truncated record header";
@@ -722,7 +716,7 @@ void ExternalFileUnit::BeginVariableFormattedInputRecord(
recordLength = length;
unterminatedRecord = true;
} else {
- handler.SignalEnd();
+ HitEndOnRead(handler);
}
break;
}
@@ -878,6 +872,13 @@ bool ExternalFileUnit::CheckDirectAccess(IoErrorHandler &handler) {
return true;
}
+void ExternalFileUnit::HitEndOnRead(IoErrorHandler &handler) {
+ handler.SignalEnd();
+ if (IsRecordFile() && access != Access::Direct) {
+ endfileRecordNumber = currentRecordNumber;
+ }
+}
+
ChildIo &ExternalFileUnit::PushChildIo(IoStatementState &parent) {
OwningPtr<ChildIo> current{std::move(child_)};
Terminator &terminator{parent.GetIoErrorHandler()};
diff --git a/flang/runtime/unit.h b/flang/runtime/unit.h
index f38f4cac19360..567aa740244ac 100644
--- a/flang/runtime/unit.h
+++ b/flang/runtime/unit.h
@@ -115,6 +115,7 @@ class ExternalFileUnit : public ConnectionState,
void DoEndfile(IoErrorHandler &);
void CommitWrites();
bool CheckDirectAccess(IoErrorHandler &);
+ void HitEndOnRead(IoErrorHandler &);
int unitNumber_{-1};
Direction direction_{Direction::Output};
More information about the flang-commits
mailing list