[PATCH] D110825: [clangd] Handle members of anon structs in SelectionTree
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 30 08:47:55 PDT 2021
kadircet updated this revision to Diff 376238.
kadircet marked 4 inline comments as done.
kadircet added a comment.
- Use `isImplicit` rather than `earlyClaim`
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D110825/new/
https://reviews.llvm.org/D110825
Files:
clang-tools-extra/clangd/Selection.cpp
clang-tools-extra/clangd/unittests/XRefsTests.cpp
Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -365,6 +365,27 @@
ElementsAre(Sym("Forward", SymbolHeader.range("forward"), Test.range())));
}
+TEST(LocateSymbol, AnonymousStructFields) {
+ auto Code = Annotations(R"cpp(
+ struct $2[[Foo]] {
+ struct { int $1[[x]]; };
+ void foo() {
+ // Make sure the implicit base is skipped.
+ $1^x = 42;
+ }
+ };
+ // Check that we don't skip explicit bases.
+ int a = $2^Foo{}.x;
+ )cpp");
+ TestTU TU = TestTU::withCode(Code.code());
+ auto AST = TU.build();
+ EXPECT_THAT(locateSymbolAt(AST, Code.point("1"), TU.index().get()),
+ UnorderedElementsAre(Sym("x", Code.range("1"), Code.range("1"))));
+ EXPECT_THAT(
+ locateSymbolAt(AST, Code.point("2"), TU.index().get()),
+ UnorderedElementsAre(Sym("Foo", Code.range("2"), Code.range("2"))));
+}
+
TEST(LocateSymbol, FindOverrides) {
auto Code = Annotations(R"cpp(
class Foo {
Index: clang-tools-extra/clangd/Selection.cpp
===================================================================
--- clang-tools-extra/clangd/Selection.cpp
+++ clang-tools-extra/clangd/Selection.cpp
@@ -443,6 +443,14 @@
if (auto *CTI = llvm::dyn_cast<CXXThisExpr>(S))
if (CTI->isImplicit())
return true;
+ // Make sure anonymous structs don't end up owning tokens.
+ if (auto *ME = llvm::dyn_cast<MemberExpr>(S)) {
+ if (auto *FD = llvm::dyn_cast<FieldDecl>(ME->getMemberDecl()))
+ if (FD->isAnonymousStructOrUnion())
+ // If the base is not implicit, it can own tokens, otherwise we should
+ // stop traversal.
+ return isImplicit(ME->getBase());
+ }
// Refs to operator() and [] are (almost?) always implicit as part of calls.
if (auto *DRE = llvm::dyn_cast<DeclRefExpr>(S)) {
if (auto *FD = llvm::dyn_cast<FunctionDecl>(DRE->getDecl())) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110825.376238.patch
Type: text/x-patch
Size: 2044 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210930/540f382f/attachment-0001.bin>
More information about the cfe-commits
mailing list