aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksandr Platonov <platonov.aleksandr@huawei.com>2025-06-13 18:32:42 +0300
committerGitHub <noreply@github.com>2025-06-13 18:32:42 +0300
commitca5040990ed17fa444d30c22fffcfa7ddc72612f (patch)
tree90e0ad06922278ab07f06a69a8f9c2a72121a8bf
parentec21b0fc9f64e8cffe689699d1e39533c62fcfc3 (diff)
downloadllvm-ca5040990ed17fa444d30c22fffcfa7ddc72612f.zip
llvm-ca5040990ed17fa444d30c22fffcfa7ddc72612f.tar.gz
llvm-ca5040990ed17fa444d30c22fffcfa7ddc72612f.tar.bz2
[clangd] Collect references in array designators (#140356)
-rw-r--r--clang-tools-extra/clangd/unittests/XRefsTests.cpp8
-rw-r--r--clang/lib/Index/IndexBody.cpp7
2 files changed, 15 insertions, 0 deletions
diff --git a/clang-tools-extra/clangd/unittests/XRefsTests.cpp b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
index 1892f87..b04d643 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 2ed20df..98ce6f7 100644
--- a/clang/lib/Index/IndexBody.cpp
+++ b/clang/lib/Index/IndexBody.cpp
@@ -435,6 +435,13 @@ public:
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;