[flang-commits] [flang] d6b7576 - [flang] Fix INQUIRE(PAD=) and (POSITION=) for predefined units
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Wed Nov 17 16:27:43 PST 2021
Author: Peter Klausler
Date: 2021-11-17T16:27:35-08:00
New Revision: d6b7576f210b6962de757c733c68fe8e96e9c760
URL: https://github.com/llvm/llvm-project/commit/d6b7576f210b6962de757c733c68fe8e96e9c760
DIFF: https://github.com/llvm/llvm-project/commit/d6b7576f210b6962de757c733c68fe8e96e9c760.diff
LOG: [flang] Fix INQUIRE(PAD=) and (POSITION=) for predefined units
The predefined units were not being initialized with FORM='FORMATTED',
so INQUIRE(PAD=) was failing if no I/O had already been done.
INQUIRE(POSITION=) was returning 'REWIND' on stdin/stdout (which
is somewhat defensible from the definition, and is what Intel Fortran
does), but most implementations return 'ASIS'. Change the runtime
to return 'REWIND' only for positionable external files, but 'ASIS'
for terminals, sockets, &c.
Differential Revision: https://reviews.llvm.org/D114028
Added:
Modified:
flang/runtime/io-stmt.cpp
flang/runtime/unit.cpp
Removed:
################################################################################
diff --git a/flang/runtime/io-stmt.cpp b/flang/runtime/io-stmt.cpp
index acb8e43cf6245..10560bfb5b30b 100644
--- a/flang/runtime/io-stmt.cpp
+++ b/flang/runtime/io-stmt.cpp
@@ -915,7 +915,7 @@ bool InquireUnitState::Inquire(
auto pos{unit().position()};
if (pos == size.value_or(pos + 1)) {
str = "APPEND";
- } else if (pos == 0) {
+ } else if (pos == 0 && unit().mayPosition()) {
str = "REWIND";
} else {
str = "ASIS"; // processor-dependent & no common behavior
diff --git a/flang/runtime/unit.cpp b/flang/runtime/unit.cpp
index 2b87d4b3ee810..1c915f3b49753 100644
--- a/flang/runtime/unit.cpp
+++ b/flang/runtime/unit.cpp
@@ -215,11 +215,13 @@ UnitMap &ExternalFileUnit::GetUnitMap() {
RUNTIME_CHECK(terminator, !wasExtant);
out.Predefine(1);
out.SetDirection(Direction::Output, handler);
+ out.isUnformatted = false;
defaultOutput = &out;
ExternalFileUnit &in{newUnitMap->LookUpOrCreate(5, terminator, wasExtant)};
RUNTIME_CHECK(terminator, !wasExtant);
in.Predefine(0);
in.SetDirection(Direction::Input, handler);
+ in.isUnformatted = false;
defaultInput = ∈
// TODO: Set UTF-8 mode from the environment
unitMap = newUnitMap;
More information about the flang-commits
mailing list