-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[clangd] fix asserts on incompatible paths in CDB #148019
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
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 llvm#146798
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-clangd Author: Dmitrii Sharshakov (dsseng) ChangesA compile_commands.json with Windows paths would make clangd assert on a Make path traversal functions skip paths of the incompatible format. Could not invent a test for this one, should be trivial enough. Fixes #146798 Full diff: https://github.com/llvm/llvm-project/pull/148019.diff 1 Files Affected:
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]));
|
@llvm/pr-subscribers-clang-tools-extra Author: Dmitrii Sharshakov (dsseng) ChangesA compile_commands.json with Windows paths would make clangd assert on a Make path traversal functions skip paths of the incompatible format. Could not invent a test for this one, should be trivial enough. Fixes #146798 Full diff: https://github.com/llvm/llvm-project/pull/148019.diff 1 Files Affected:
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]));
|
Sorry if I'm wrong with the choice of reviewers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if I identified all the places where traversal with attempts to find parent path is done, but it does not assert now when running Helix in a provided sample project
You can test this locally with the following command:git-clang-format --diff HEAD~1 HEAD --extensions cpp -- clang-tools-extra/clangd/GlobalCompilationDatabase.cpp View the diff from clang-format here.diff --git a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
index 4d934d268..dd1aa2a1a 100644
--- a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
+++ b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
@@ -684,7 +684,8 @@ public:
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))
+ if (!llvm::sys::path::is_absolute(AllFiles[I],
+ llvm::sys::path::Style::native))
continue;
if (ExitEarly()) // loading config may be slow
return Filtered;
|
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