diff --git a/llvm/lib/Support/VirtualFileSystem.cpp b/llvm/lib/Support/VirtualFileSystem.cpp --- a/llvm/lib/Support/VirtualFileSystem.cpp +++ b/llvm/lib/Support/VirtualFileSystem.cpp @@ -1041,9 +1041,10 @@ // Detect the path style in use by checking the first separator. llvm::sys::path::Style style = llvm::sys::path::Style::native; const size_t n = Path.find_first_of("/\\"); + // Can't distinguish between posix and windows_slash here. if (n != static_cast(-1)) style = (Path[n] == '/') ? llvm::sys::path::Style::posix - : llvm::sys::path::Style::windows; + : llvm::sys::path::Style::windows_backslash; return style; } @@ -1187,8 +1188,10 @@ } std::error_code RedirectingFileSystem::makeAbsolute(SmallVectorImpl &Path) const { + // is_absolute(..., Style::windows_*) accepts paths with both slash types. if (llvm::sys::path::is_absolute(Path, llvm::sys::path::Style::posix) || - llvm::sys::path::is_absolute(Path, llvm::sys::path::Style::windows)) + llvm::sys::path::is_absolute(Path, + llvm::sys::path::Style::windows_backslash)) return {}; auto WorkingDir = getCurrentWorkingDirectory(); @@ -1199,9 +1202,15 @@ // is native and there is no way to override that. Since we know WorkingDir // is absolute, we can use it to determine which style we actually have and // append Path ourselves. - sys::path::Style style = sys::path::Style::windows; + sys::path::Style style = sys::path::Style::windows_backslash; if (sys::path::is_absolute(WorkingDir.get(), sys::path::Style::posix)) { style = sys::path::Style::posix; + } else { + // Distinguish between windows_backslash and windows_slash; getExistingStyle + // returns posix for a path with windows_slash. + if (getExistingStyle(WorkingDir.get()) != + sys::path::Style::windows_backslash) + style = sys::path::Style::windows_slash; } std::string Result = WorkingDir.get(); @@ -1619,8 +1628,9 @@ // which style we have, and use it consistently. if (sys::path::is_absolute(Name, sys::path::Style::posix)) { path_style = sys::path::Style::posix; - } else if (sys::path::is_absolute(Name, sys::path::Style::windows)) { - path_style = sys::path::Style::windows; + } else if (sys::path::is_absolute(Name, + sys::path::Style::windows_backslash)) { + path_style = sys::path::Style::windows_backslash; } else { assert(NameValueNode && "Name presence should be checked earlier"); error(NameValueNode,