denis-fatkulin created this revision. denis-fatkulin added a reviewer: hokein. Herald added subscribers: usaxena95, kadircet, arphaman. Herald added a project: All. denis-fatkulin requested review of this revision. Herald added projects: clang, clang-tools-extra. Herald added a subscriber: cfe-commits.
Unresolved member expressions aren't indexed as references. Example code: struct Foo { template <typename T> void $decl[[bar]](T t); }; template <typename T> void test(Foo F, T t) { F.bar(t); // Not indexed } Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D131091 Files: clang-tools-extra/clangd/unittests/XRefsTests.cpp clang/lib/Index/IndexBody.cpp clang/test/Index/Core/index-dependent-source.cpp clang/unittests/Index/IndexTests.cpp Index: clang/unittests/Index/IndexTests.cpp =================================================================== --- clang/unittests/Index/IndexTests.cpp +++ clang/unittests/Index/IndexTests.cpp @@ -392,6 +392,36 @@ Contains(AllOf(QName("MyTypedef"), HasRole(SymbolRole::Reference), WrittenAt(Position(4, 16)))))); } + +TEST(IndexTest, UnresolvedLookupExpr) { + std::string Code = R"cpp( + template <typename T> void foo(T t); + template <typename T> void test(T t) { + foo(t); + } + )cpp"; + auto Index = std::make_shared<Indexer>(); + tooling::runToolOnCode(std::make_unique<IndexAction>(Index), Code); + EXPECT_THAT(Index->Symbols, + Contains(AllOf(QName("foo"), HasRole(SymbolRole::Reference), + WrittenAt(Position(4, 7))))); +} + +TEST(IndexTest, UnresolvedMemberExpr) { + std::string Code = R"cpp( + struct Foo { + template <typename T> void bar(T t); + }; + template <typename T> void test(Foo F, T t) { + F.bar(t); + } + )cpp"; + auto Index = std::make_shared<Indexer>(); + tooling::runToolOnCode(std::make_unique<IndexAction>(Index), Code); + EXPECT_THAT(Index->Symbols, + Contains(AllOf(QName("Foo::bar"), HasRole(SymbolRole::Reference), + WrittenAt(Position(6, 9))))); +} } // namespace } // namespace index } // namespace clang Index: clang/test/Index/Core/index-dependent-source.cpp =================================================================== --- clang/test/Index/Core/index-dependent-source.cpp +++ clang/test/Index/Core/index-dependent-source.cpp @@ -231,3 +231,12 @@ foo<T>(); // CHECK: [[@LINE-1]]:3 | function/C | foo | c:@FT@>1#Tfoo#v# | <no-cgname> | Ref,Call,RelCall,RelCont | rel: 1 } + +struct Foo { + template <typename T> void bar(); + // CHECK: [[@LINE-1]]:30 | instance-method/C++ | bar | c:@S@Foo@FT@>1#Tbar#v# | <no-cgname> | Decl,RelChild | rel: 1 +}; +template <typename T> void baz(Foo f) { + f.bar<T>(); + // CHECK: [[@LINE-1]]:5 | instance-method/C++ | bar | c:@S@Foo@FT@>1#Tbar#v# | <no-cgname> | Ref,Call,RelCall,RelCont | rel: 1 +} Index: clang/lib/Index/IndexBody.cpp =================================================================== --- clang/lib/Index/IndexBody.cpp +++ clang/lib/Index/IndexBody.cpp @@ -468,7 +468,7 @@ return true; } - bool VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) { + bool VisitOverloadExpr(OverloadExpr *E) { SmallVector<SymbolRelation, 4> Relations; SymbolRoleSet Roles = getRolesForRef(E, Relations); for (auto *D : E->decls()) Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/XRefsTests.cpp +++ clang-tools-extra/clangd/unittests/XRefsTests.cpp @@ -2090,6 +2090,14 @@ [[f^oo]](s); } )cpp", + R"cpp(// unresolved member expression + struct Foo { + template <typename T> void $decl[[bar]](T t); + }; + template <typename T> void test(Foo F, T t) { + F.[[b^ar]](t); + } + )cpp", // Enum base R"cpp(
Index: clang/unittests/Index/IndexTests.cpp =================================================================== --- clang/unittests/Index/IndexTests.cpp +++ clang/unittests/Index/IndexTests.cpp @@ -392,6 +392,36 @@ Contains(AllOf(QName("MyTypedef"), HasRole(SymbolRole::Reference), WrittenAt(Position(4, 16)))))); } + +TEST(IndexTest, UnresolvedLookupExpr) { + std::string Code = R"cpp( + template <typename T> void foo(T t); + template <typename T> void test(T t) { + foo(t); + } + )cpp"; + auto Index = std::make_shared<Indexer>(); + tooling::runToolOnCode(std::make_unique<IndexAction>(Index), Code); + EXPECT_THAT(Index->Symbols, + Contains(AllOf(QName("foo"), HasRole(SymbolRole::Reference), + WrittenAt(Position(4, 7))))); +} + +TEST(IndexTest, UnresolvedMemberExpr) { + std::string Code = R"cpp( + struct Foo { + template <typename T> void bar(T t); + }; + template <typename T> void test(Foo F, T t) { + F.bar(t); + } + )cpp"; + auto Index = std::make_shared<Indexer>(); + tooling::runToolOnCode(std::make_unique<IndexAction>(Index), Code); + EXPECT_THAT(Index->Symbols, + Contains(AllOf(QName("Foo::bar"), HasRole(SymbolRole::Reference), + WrittenAt(Position(6, 9))))); +} } // namespace } // namespace index } // namespace clang Index: clang/test/Index/Core/index-dependent-source.cpp =================================================================== --- clang/test/Index/Core/index-dependent-source.cpp +++ clang/test/Index/Core/index-dependent-source.cpp @@ -231,3 +231,12 @@ foo<T>(); // CHECK: [[@LINE-1]]:3 | function/C | foo | c:@FT@>1#Tfoo#v# | <no-cgname> | Ref,Call,RelCall,RelCont | rel: 1 } + +struct Foo { + template <typename T> void bar(); + // CHECK: [[@LINE-1]]:30 | instance-method/C++ | bar | c:@S@Foo@FT@>1#Tbar#v# | <no-cgname> | Decl,RelChild | rel: 1 +}; +template <typename T> void baz(Foo f) { + f.bar<T>(); + // CHECK: [[@LINE-1]]:5 | instance-method/C++ | bar | c:@S@Foo@FT@>1#Tbar#v# | <no-cgname> | Ref,Call,RelCall,RelCont | rel: 1 +} Index: clang/lib/Index/IndexBody.cpp =================================================================== --- clang/lib/Index/IndexBody.cpp +++ clang/lib/Index/IndexBody.cpp @@ -468,7 +468,7 @@ return true; } - bool VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) { + bool VisitOverloadExpr(OverloadExpr *E) { SmallVector<SymbolRelation, 4> Relations; SymbolRoleSet Roles = getRolesForRef(E, Relations); for (auto *D : E->decls()) Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/XRefsTests.cpp +++ clang-tools-extra/clangd/unittests/XRefsTests.cpp @@ -2090,6 +2090,14 @@ [[f^oo]](s); } )cpp", + R"cpp(// unresolved member expression + struct Foo { + template <typename T> void $decl[[bar]](T t); + }; + template <typename T> void test(Foo F, T t) { + F.[[b^ar]](t); + } + )cpp", // Enum base R"cpp(
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits