diff --git a/clang-tools-extra/clangd/PathMapping.cpp b/clang-tools-extra/clangd/PathMapping.cpp index 4b93ff2c60c5c..48a936867a738 100644 --- a/clang-tools-extra/clangd/PathMapping.cpp +++ b/clang-tools-extra/clangd/PathMapping.cpp @@ -150,11 +150,11 @@ llvm::Expected parsePath(llvm::StringRef Path) { if (path::is_absolute(Path, path::Style::posix)) { return std::string(Path); } - if (path::is_absolute(Path, path::Style::windows)) { - std::string Converted = path::convert_to_slash(Path, path::Style::windows); - if (Converted.front() != '/') - Converted = "/" + Converted; - return Converted; + llvm::StringRef Root = path::root_name(Path, path::Style::windows); + if (!Root.empty()) { + std::string Converted = "/"; + return Converted.append(Root) + .append(path::convert_to_slash(Path.substr(Root.size()), path::Style::windows)); } return error("Path not absolute: {0}", Path); }