[PATCH] D46621: [Support] call FlushFileBuffers when closing raw_fd_ostream on Windows

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Tue May 8 19:31:53 PDT 2018


This doesn’t seem necessary, as the problem in the referenced cl only
affects memory mapped files. Furthermore, this will probably adversely
impact performance.
On Tue, May 8, 2018 at 7:27 PM Bob Haarman via Phabricator <
reviews at reviews.llvm.org> wrote:

> inglorion created this revision.
> inglorion added reviewers: rnk, zturner.
> Herald added subscribers: hiraditya, mehdi_amini.
>
> We have observed a problem where files we write on Windows are
> sometimes read back with bytes having value 0, when that was not the
> value that was written. https://reviews.llvm.org/D42925 works around this
> problem for files we
> write to by memory-mapping them. This change applies a similar fix for
> files we write using raw_fd_ostream, as we do for archives and in the
> LTO cache.
>
>
> https://reviews.llvm.org/D46621
>
> Files:
>   llvm/lib/Support/raw_ostream.cpp
>
>
> Index: llvm/lib/Support/raw_ostream.cpp
> ===================================================================
> --- llvm/lib/Support/raw_ostream.cpp
> +++ llvm/lib/Support/raw_ostream.cpp
> @@ -551,6 +551,15 @@
>    if (FD >= 0) {
>      flush();
>      if (ShouldClose) {
> +#if defined(LLVM_ON_WIN32)
> +      // On Windows, we have observed that programs that read a file
> after it
> +      // was written will sometimes read bytes with value 0, when that
> isn't
> +      // actually the value that was written. Calling FlushFileBuffers
> before
> +      // closing the file seems to avoid the issue.
> +      HANDLE FileHandle = reinterpret_cast<HANDLE>(_get_osfhandle(FD));
> +      if (FileHandle != INVALID_HANDLE_VALUE)
> +        ::FlushFileBuffers(FileHandle);
> +#endif
>        if (auto EC = sys::Process::SafelyCloseFileDescriptor(FD))
>          error_detected(EC);
>      }
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180509/8bf351c6/attachment.html>


More information about the llvm-commits mailing list