[clang] 6c47eaf - [clang][index] report references from unreslovedLookupExpr.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 11 02:08:41 PST 2021
Author: Haojian Wu
Date: 2021-02-11T11:08:26+01:00
New Revision: 6c47eafb3973a8e3f7455c9655ed666883e7b513
URL: https://github.com/llvm/llvm-project/commit/6c47eafb3973a8e3f7455c9655ed666883e7b513
DIFF: https://github.com/llvm/llvm-project/commit/6c47eafb3973a8e3f7455c9655ed666883e7b513.diff
LOG: [clang][index] report references from unreslovedLookupExpr.
Fix https://github.com/clangd/clangd/issues/675
Differential Revision: https://reviews.llvm.org/D96262
Added:
Modified:
clang-tools-extra/clangd/unittests/XRefsTests.cpp
clang/lib/Index/IndexBody.cpp
clang/test/Index/Core/index-dependent-source.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/unittests/XRefsTests.cpp b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
index a7715900ab97..9d77e0fb291a 100644
--- a/clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1863,6 +1863,26 @@ TEST(FindReferences, WithinAST) {
Vector<int> x2;
Vector<double> y;
)cpp",
+ R"cpp(// Dependent code
+ template <typename T> void $decl[[foo]](T t);
+ template <typename T> void bar(T t) { [[foo]](t); } // foo in bar is uninstantiated.
+ void baz(int x) { [[f^oo]](x); }
+ )cpp",
+ R"cpp(
+ namespace ns {
+ struct S{};
+ void $decl[[foo]](S s);
+ } // namespace ns
+ template <typename T> void foo(T t);
+ // FIXME: Maybe report this foo as a ref to ns::foo (because of ADL)
+ // when bar<ns::S> is instantiated?
+ template <typename T> void bar(T t) { foo(t); }
+ void baz(int x) {
+ ns::S s;
+ bar<ns::S>(s);
+ [[f^oo]](s);
+ }
+ )cpp",
};
for (const char *Test : Tests)
checkFindRefs(Test);
diff --git a/clang/lib/Index/IndexBody.cpp b/clang/lib/Index/IndexBody.cpp
index e4944fd0fc3b..7279e3b53c81 100644
--- a/clang/lib/Index/IndexBody.cpp
+++ b/clang/lib/Index/IndexBody.cpp
@@ -466,6 +466,15 @@ class BodyIndexer : public RecursiveASTVisitor<BodyIndexer> {
}
return true;
}
+
+ bool VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
+ SmallVector<SymbolRelation, 4> Relations;
+ SymbolRoleSet Roles = getRolesForRef(E, Relations);
+ for (auto *D : E->decls())
+ IndexCtx.handleReference(D, E->getNameLoc(), Parent, ParentDC, Roles,
+ Relations, E);
+ return true;
+ }
};
} // anonymous namespace
diff --git a/clang/test/Index/Core/index-dependent-source.cpp b/clang/test/Index/Core/index-dependent-source.cpp
index 2e111339af61..8832edefd5bf 100644
--- a/clang/test/Index/Core/index-dependent-source.cpp
+++ b/clang/test/Index/Core/index-dependent-source.cpp
@@ -224,3 +224,10 @@ struct UsingE : public UsingD<T>, public UsingD<U> {
// CHECK: [[@LINE+1]]:9 | struct(Gen)/C++ | UsingD | c:@ST>1#T at UsingD | <no-cgname> | Ref,RelCont | rel: 1
using UsingD<U>::foo;
};
+
+template <typename T> void foo();
+// CHECK: [[@LINE-1]]:28 | function/C | foo | c:@FT@>1#Tfoo#v# | <no-cgname> | Decl | rel: 0
+template <typename T> void bar() {
+ foo<T>();
+// CHECK: [[@LINE-1]]:3 | function/C | foo | c:@FT@>1#Tfoo#v# | <no-cgname> | Ref,Call,RelCall,RelCont | rel: 1
+}
More information about the cfe-commits
mailing list