[flang-commits] [PATCH] D114028: [flang] Fix INQUIRE(PAD=) and (POSITION=) for predefined units
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Tue Nov 16 13:47:32 PST 2021
klausler created this revision.
klausler added a reviewer: Renaud-K.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
klausler requested review of this revision.
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.
https://reviews.llvm.org/D114028
Files:
flang/runtime/io-stmt.cpp
flang/runtime/unit.cpp
Index: flang/runtime/unit.cpp
===================================================================
--- flang/runtime/unit.cpp
+++ flang/runtime/unit.cpp
@@ -215,11 +215,13 @@
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;
Index: flang/runtime/io-stmt.cpp
===================================================================
--- flang/runtime/io-stmt.cpp
+++ flang/runtime/io-stmt.cpp
@@ -915,7 +915,7 @@
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114028.387752.patch
Type: text/x-patch
Size: 1132 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20211116/69dbfcea/attachment.bin>
More information about the flang-commits
mailing list