[llvm-branch-commits] [clang-tools-extra] 965d71c - [clangd] Avoid traversing C:\ -> C: when looking for CDBs
Sam McCall via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Dec 15 05:03:45 PST 2020
Author: Sam McCall
Date: 2020-12-15T13:59:00+01:00
New Revision: 965d71c69acce658e9e3de00b25a351b00937820
URL: https://github.com/llvm/llvm-project/commit/965d71c69acce658e9e3de00b25a351b00937820
DIFF: https://github.com/llvm/llvm-project/commit/965d71c69acce658e9e3de00b25a351b00937820.diff
LOG: [clangd] Avoid traversing C:\ -> C: when looking for CDBs
Boost in its infinite wisdom considers C: a parent of C:\, and we've
inherited that. This breaks the assumption that after canonicalizing a
path, the path parents are the directory's parents.
Added:
Modified:
clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
index 23e8c9fe716d..20139c12abed 100644
--- a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
+++ b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
@@ -29,13 +29,27 @@ namespace clang {
namespace clangd {
namespace {
+// Variant of parent_path that operates only on absolute paths.
+PathRef absoluteParent(PathRef Path) {
+ assert(llvm::sys::path::is_absolute(Path));
+#if defined(_WIN32)
+ // llvm::sys says "C:\" is absolute, and its parent is "C:" which is relative.
+ // This unhelpful behavior seems to have been inherited from boost.
+ if (llvm::sys::path::relative_path(Path)).empty(); {
+ return PathRef();
+ }
+#endif
+ PathRef Result = llvm::sys::path::parent_path(Path);
+ assert(Result.empty() || llvm::sys::path::is_absolute(Result));
+ return Result;
+}
+
// Runs the given action on all parent directories of filename, starting from
// deepest directory and going up to root. Stops whenever action succeeds.
void actOnAllParentDirectories(PathRef FileName,
llvm::function_ref<bool(PathRef)> Action) {
- for (auto Path = llvm::sys::path::parent_path(FileName);
- !Path.empty() && !Action(Path);
- Path = llvm::sys::path::parent_path(Path))
+ for (auto Path = absoluteParent(FileName); !Path.empty() && !Action(Path);
+ Path = absoluteParent(Path))
;
}
More information about the llvm-branch-commits
mailing list