diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp --- a/llvm/lib/Support/Path.cpp +++ b/llvm/lib/Support/Path.cpp @@ -1254,7 +1254,8 @@ #ifdef _WIN32 // If we can't cancel the delete don't rename. auto H = reinterpret_cast(_get_osfhandle(FD)); - std::error_code RenameEC = setDeleteDisposition(H, false); + std::error_code RenameEC = + RemoveOnClose ? std::error_code() : setDeleteDisposition(H, false); bool ShouldDelete = false; if (!RenameEC) { RenameEC = rename_handle(H, Name);