From: Kadir Cetinkaya Date: Fri, 8 Mar 2019 09:54:37 +0000 (+0000) Subject: [clangd] Make sure constructors do not reference class X-Git-Tag: llvmorg-10-init~10441 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=017cc6c190e2d22f23fba4c178934f6e4e03db0c;p=platform%2Fupstream%2Fllvm.git [clangd] Make sure constructors do not reference class Reviewers: gribozavr Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58815 llvm-svn: 355679 --- diff --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp index be4df73..a099fb9 100644 --- a/clang-tools-extra/clangd/XRefs.cpp +++ b/clang-tools-extra/clangd/XRefs.cpp @@ -15,6 +15,7 @@ #include "clang/AST/DeclTemplate.h" #include "clang/AST/RecursiveASTVisitor.h" #include "clang/Index/IndexDataConsumer.h" +#include "clang/Index/IndexSymbol.h" #include "clang/Index/IndexingAction.h" #include "clang/Index/USRGeneration.h" #include "llvm/Support/Path.h" @@ -154,6 +155,10 @@ public: llvm::ArrayRef Relations, SourceLocation Loc, index::IndexDataConsumer::ASTNodeInfo ASTNode) override { + // Skip non-semantic references. + if (Roles & static_cast(index::SymbolRole::NameReference)) + return true; + if (Loc == SearchedLocation) { auto IsImplicitExpr = [](const Expr *E) { if (!E) diff --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp b/clang-tools-extra/clangd/index/SymbolCollector.cpp index 686b67b..7fae079 100644 --- a/clang-tools-extra/clangd/index/SymbolCollector.cpp +++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp @@ -211,7 +211,7 @@ getTokenLocation(SourceLocation TokLoc, const SourceManager &SM, // the first seen declaration as canonical declaration is not a good enough // heuristic. bool isPreferredDeclaration(const NamedDecl &ND, index::SymbolRoleSet Roles) { - const auto& SM = ND.getASTContext().getSourceManager(); + const auto &SM = ND.getASTContext().getSourceManager(); return (Roles & static_cast(index::SymbolRole::Definition)) && isa(&ND) && !SM.isWrittenInMainFile(SM.getExpansionLoc(ND.getLocation())); @@ -305,6 +305,10 @@ bool SymbolCollector::handleDeclOccurence( Decl::FriendObjectKind::FOK_None) && !(Roles & static_cast(index::SymbolRole::Definition))) return true; + // Skip non-semantic references, we should start processing these when we + // decide to implement renaming with index support. + if ((Roles & static_cast(index::SymbolRole::NameReference))) + return true; // A declaration created for a friend declaration should not be used as the // canonical declaration in the index. Use OrigD instead, unless we've already // picked a replacement for D diff --git a/clang-tools-extra/unittests/clangd/XRefsTests.cpp b/clang-tools-extra/unittests/clangd/XRefsTests.cpp index df795b1..1f0f808 100644 --- a/clang-tools-extra/unittests/clangd/XRefsTests.cpp +++ b/clang-tools-extra/unittests/clangd/XRefsTests.cpp @@ -1337,6 +1337,15 @@ TEST(FindReferences, WithinAST) { } )cpp", + R"cpp(// Constructor + struct Foo { + [[F^oo]](int); + }; + void foo() { + Foo f = [[Foo]](42); + } + )cpp", + R"cpp(// Typedef typedef int [[Foo]]; int main() {