-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clangd] Collect references in array designators #140356
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
Conversation
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clangd Author: Aleksandr Platonov (ArcsinX) ChangesWithout this patch clangd doesn't collect references in array designators. E.g. Find All References for symbol const int Foo = 0;
int Bar[] = {
[Foo...Foo + 1] = 0,
[Foo + 2] = 1
}; Full diff: https://github.com/llvm/llvm-project/pull/140356.diff 2 Files Affected:
diff --git a/clang-tools-extra/clangd/unittests/XRefsTests.cpp b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
index 1892f87c8e82a..b04d6431f89f9 100644
--- a/clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -2311,6 +2311,14 @@ TEST(FindReferences, WithinAST) {
$(S::deleteObject)[[de^lete]] S;
}
};
+ )cpp",
+ // Array designators
+ R"cpp(
+ const int $def[[F^oo]] = 0;
+ int Bar[] = {
+ [$(Bar)[[F^oo]]...$(Bar)[[Fo^o]] + 1] = 0,
+ [$(Bar)[[^Foo]] + 2] = 1
+ };
)cpp"};
for (const char *Test : Tests)
checkFindRefs(Test);
diff --git a/clang/lib/Index/IndexBody.cpp b/clang/lib/Index/IndexBody.cpp
index 2ed20df22bda0..98ce6f73ec849 100644
--- a/clang/lib/Index/IndexBody.cpp
+++ b/clang/lib/Index/IndexBody.cpp
@@ -435,6 +435,13 @@ class BodyIndexer : public RecursiveASTVisitor<BodyIndexer> {
ParentDC, SymbolRoleSet(),
/*Relations=*/{}, E);
}
+ } else {
+ if (D.isArrayDesignator())
+ TraverseStmt(E->getArrayIndex(D));
+ else if (D.isArrayRangeDesignator()) {
+ TraverseStmt(E->getArrayRangeStart(D));
+ TraverseStmt(E->getArrayRangeEnd(D));
+ }
}
}
return true;
|
Friendly ping |
Maybe someone can take a look at this? The diff is very small. |
Ping |
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.
sorry for the late response and thanks a lot!
ab701eb
to
516384e
Compare
516384e
to
c443180
Compare
Thank you for review! |
Without this patch clangd doesn't collect references in array designators. E.g. Find All References for symbol
Foo
in the following code gives only 1 result (in definition):