[clang-tools-extra] [clangd] fix asserts on incompatible paths in CDB (PR #148019)
Dmitrii Sharshakov via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 10 11:15:20 PDT 2025
https://github.com/dsseng created https://github.com/llvm/llvm-project/pull/148019
A compile_commands.json with Windows paths would make clangd assert on a
POSIX system, and vice versa.
Make path traversal functions skip paths of the incompatible format.
Could not invent a test for this one, should be trivial enough.
Fixes #146798
>From a7bed3e996eda21875b307384b05e78ef044ff45 Mon Sep 17 00:00:00 2001
From: Dmitrii Sharshakov <d3dx12.xx at gmail.com>
Date: Thu, 10 Jul 2025 20:09:57 +0200
Subject: [PATCH] [clangd] fix asserts on incompatible paths in CDB
A compile_commands.json with Windows paths would make clangd assert on a
POSIX system, and vice versa.
Make path traversal functions skip paths of the incompatible format.
Could not invent a test for this one, should be trivial enough.
Fixes #146798
---
clang-tools-extra/clangd/GlobalCompilationDatabase.cpp | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
index 7c0eb9651feaa..4d934d268fdfd 100644
--- a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
+++ b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
@@ -47,6 +47,9 @@ namespace {
// deepest directory and going up to root. Stops whenever action succeeds.
void actOnAllParentDirectories(PathRef FileName,
llvm::function_ref<bool(PathRef)> Action) {
+ // Skip non-native paths which we cannot traverse or otherwise use.
+ if (!llvm::sys::path::is_absolute(FileName, llvm::sys::path::Style::native))
+ return;
for (auto Path = absoluteParent(FileName); !Path.empty() && !Action(Path);
Path = absoluteParent(Path))
;
@@ -680,6 +683,9 @@ class DirectoryBasedGlobalCompilationDatabase::BroadcastThread::Filter {
SearchPaths[I].setPointer(&Dirs[*Parent.Opts.CompileCommandsDir]);
continue;
}
+ // Skip non-native paths which we cannot traverse or otherwise use.
+ if (!llvm::sys::path::is_absolute(AllFiles[I], llvm::sys::path::Style::native))
+ continue;
if (ExitEarly()) // loading config may be slow
return Filtered;
WithContext WithProvidedContent(Parent.Opts.ContextProvider(AllFiles[I]));
More information about the cfe-commits
mailing list