[flang][runtime] Reset unit frame buffer when re-opening
authorPeter Klausler <pklausler@nvidia.com>
Fri, 22 Jul 2022 21:32:03 +0000 (14:32 -0700)
committerPeter Klausler <pklausler@nvidia.com>
Mon, 25 Jul 2022 19:18:14 +0000 (12:18 -0700)
An OPEN statement that implies closing a connection must invalidate
the unit's frame buffer so as to prevent stale data from the old
connection from being read into the newly-connected unit.

Differential Revision: https://reviews.llvm.org/D130430

flang/runtime/unit.cpp

index 018c433..12d8dbc 100644 (file)
@@ -114,6 +114,7 @@ void ExternalFileUnit::OpenUnit(std::optional<OpenStatus> status,
     // Otherwise, OPEN on open unit with new FILE= implies CLOSE
     DoImpliedEndfile(handler);
     FlushOutput(handler);
+    TruncateFrame(0, handler);
     Close(CloseStatus::Keep, handler);
   }
   if (newPath.get() && newPathLength > 0) {