This is an archive of the discontinued LLVM Phabricator instance.

FileOutputBuffer : Fix undefined behavior on windows
Needs ReviewPublic

Authored by shankare on May 5 2016, 9:25 AM.

Details

Summary

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.

Diff Detail

Event Timeline

shankare updated this revision to Diff 56299.May 5 2016, 9:25 AM
shankare retitled this revision from to FileOutputBuffer : Fix undefined behavior on windows.
shankare updated this object.
shankare added reviewers: ruiu, colinl, adasgupt, khemant.
shankare set the repository for this revision to rL LLVM.
shankare added a subscriber: llvm-commits.
ruiu edited edge metadata.May 5 2016, 6:54 PM

What is the problem you are trying to fix? The current code is working fine for both non-Windows and Windows. This patch would make this function very slow on Windows.

I was trying to debug a problem with the usage of FileOutputBuffer where the memory contents are not being synced to disk. I traced every call in FileOutputBuffer and none of the calls return an error, but the file is not synced. This happens on windows systems with FAST IO enabled. Resizing the underlying file makes the problem disappear.

ruiu added a comment.May 9 2016, 3:20 PM

Please share minimal code to reproduce the problem to let me assess it.

I totally forgot about your comment, I will respond to you with a testcase shortly.