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

Michael Kruse via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 3 16:59:00 PST 2022


Meinersbur added a comment.

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.


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