[PATCH] D118834: [flang] Debugging of ACCESS='STREAM' I/O

Peter Klausler via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 3 17:31:47 PST 2022


klausler added a comment.

In D118834#3295507 <https://reviews.llvm.org/D118834#3295507>, @Meinersbur wrote:

> The runtime uses a temporary file in scratch mode that the unittest uses, which is opened in text mode. Under Windows, when writing `\n` to a file opened in text mode, it will actually write `\r\n`. However, the internal position counter `frameOffsetInFile_` will not take the additional character into account. On Rewind, it will truncate the file to the `frameOffsetInFile_` size, keeping the first `\r` but truncating the second character `\n` away.
>
> This makes the test pass:
>
>   diff --git a/flang/runtime/file.cpp b/flang/runtime/file.cpp
>   index 4e36978cfb23..787845f78353 100644
>   --- a/flang/runtime/file.cpp
>   +++ b/flang/runtime/file.cpp
>   @@ -46,7 +46,7 @@ static int openfile_mkstemp(IoErrorHandler &handler) {
>        return -1;
>      }
>      int fd{::_open(
>   -      tempFileName, _O_CREAT | _O_TEMPORARY | _O_RDWR, _S_IREAD | _S_IWRITE)};
>   +      tempFileName, _O_CREAT | _O_BINARY | _O_TEMPORARY | _O_RDWR, _S_IREAD | _S_IWRITE)};
>    #else
>      char path[]{"/tmp/Fortran-Scratch-XXXXXX"};
>      int fd{::mkstemp(path)};
>
> However, I don't think this is an universal solution, as stdout and stderr are always in text mode.

Thanks, that's a helpful clue.  Unfortunately in Fortran we can't always know whether a file will be formatted or unformatted at the time that the file is opened, so the runtime will probably have to always use binary mode and emit explicit carriage returns.  Stdout and stderr being in text mode is not much of a problem -- they don't have to be positionable and are always formatted.  I will get back to this in a few weeks after I dig out from under a pile of more important things.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D118834/new/

https://reviews.llvm.org/D118834



More information about the llvm-commits mailing list