Index: llvm/lib/Support/Windows/Path.inc =================================================================== --- llvm/lib/Support/Windows/Path.inc +++ llvm/lib/Support/Windows/Path.inc @@ -259,26 +259,21 @@ std::error_code remove(const Twine &path, bool IgnoreNonExisting) { SmallVector path_utf16; - file_status ST; - if (std::error_code EC = status(path, ST)) { - if (EC != errc::no_such_file_or_directory || !IgnoreNonExisting) - return EC; - return std::error_code(); - } - if (std::error_code ec = widenPath(path, path_utf16)) return ec; - if (ST.type() == file_type::directory_file) { - if (!::RemoveDirectoryW(c_str(path_utf16))) { - std::error_code EC = mapWindowsError(::GetLastError()); - if (EC != errc::no_such_file_or_directory || !IgnoreNonExisting) - return EC; - } - return std::error_code(); - } + // Speculate that the path is actually a file in order to save a stat() call. if (!::DeleteFileW(c_str(path_utf16))) { std::error_code EC = mapWindowsError(::GetLastError()); + if (EC == errc::permission_denied) { + if (!::RemoveDirectoryW(c_str(path_utf16))) { + std::error_code EC = mapWindowsError(::GetLastError()); + if (EC != errc::no_such_file_or_directory || !IgnoreNonExisting) + return EC; + } + return std::error_code(); + } + if (EC != errc::no_such_file_or_directory || !IgnoreNonExisting) return EC; }