Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions llvm/lib/CAS/MappedFileRegionArena.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,14 @@ void MappedFileRegionArena::destroyImpl() {
}
}

#ifdef _WIN32
// Always Unmap to
// - avoid address space leak;
// - avoid data loss for sparse files.
if (Region)
Region.unmap();
#endif

auto Close = [](std::optional<int> &FD) {
if (FD) {
sys::fs::file_t File = sys::fs::convertFDToNativeFile(*FD);
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/Support/Windows/Path.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,10 @@ static bool isEXE(StringRef Magic) {

void mapped_file_region::unmapImpl() {
if (Mapping) {
BY_HANDLE_FILE_INFORMATION FI;
if (::GetFileInformationByHandle(FileHandle.get(), &FI) &&
(FI.dwFileAttributes & FILE_ATTRIBUTE_SPARSE_FILE) != 0)
::FlushViewOfFile(Mapping, Size);

bool Exe = isEXE(StringRef((char *)Mapping, Size));

Expand Down