[PATCH] D19982: FileOutputBuffer : Fix undefined behavior on windows

Shankar Easwaran via llvm-commits llvm-commits at lists.llvm.org
Thu May 5 09:25:34 PDT 2016


shankare created this revision.
shankare added reviewers: ruiu, colinl, adasgupt, khemant.
shankare added a subscriber: llvm-commits.
shankare set the repository for this revision to rL LLVM.

A memory buffer backedup by a fd, shows undefined behavior if the fd is not resized appropriately. This shows up on file systems mounted on windows, the files end up with all bytes 0'ed. 

Repository:
  rL LLVM

http://reviews.llvm.org/D19982

Files:
  lib/Support/FileOutputBuffer.cpp

Index: lib/Support/FileOutputBuffer.cpp
===================================================================
--- lib/Support/FileOutputBuffer.cpp
+++ lib/Support/FileOutputBuffer.cpp
@@ -77,16 +77,11 @@
 
   sys::RemoveFileOnSignal(TempFilePath);
 
-#ifndef LLVM_ON_WIN32
-  // On Windows, CreateFileMapping (the mmap function on Windows)
-  // automatically extends the underlying file. We don't need to
-  // extend the file beforehand. _chsize (ftruncate on Windows) is
-  // pretty slow just like it writes specified amount of bytes,
-  // so we should avoid calling that.
+  // The behavior is defined by the file system. On filesystems
+  // backed by NFS, this is essential.
   EC = sys::fs::resize_file(FD, Size);
   if (EC)
     return EC;
-#endif
 
   auto MappedFile = llvm::make_unique<mapped_file_region>(
       FD, mapped_file_region::readwrite, Size, 0, EC);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19982.56299.patch
Type: text/x-patch
Size: 874 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160505/a3f6e712/attachment.bin>


More information about the llvm-commits mailing list