[flang] Fix output buffering bug (positionability assumption)
authorpeter klausler <pklausler@nvidia.com>
Tue, 23 Mar 2021 20:57:00 +0000 (13:57 -0700)
committerpeter klausler <pklausler@nvidia.com>
Wed, 24 Mar 2021 18:39:18 +0000 (11:39 -0700)
commit5da55bfc18f64b7171be150913e2f5eac6e0f184
tree47941fe12baa8cb85de9df3da5360ee03f70217e
parent3cb2346982399892eae36e660ffa7e77a27ee067
[flang] Fix output buffering bug (positionability assumption)

The I/O runtime library code was failing to retain data in a buffer
from the current output record when flushing the buffer; this is
fatally wrong when the corresponding file cannot be repositioned,
as in the case of standard output to the console. So refine the
Flush() member function to retain a specified number of bytes,
rearrange the data as necessary (using existing code for read frame
management after moving it into a new member function), and add
a big comment to the head of the file to clarify the roles of the
various data members in the management of contiguous frames in
circular buffers.

Update: added a unit test.

Differential Revision: https://reviews.llvm.org/D99198
flang/runtime/buffer.h
flang/unittests/Runtime/CMakeLists.txt
flang/unittests/Runtime/buffer.cpp [new file with mode: 0644]