[PATCH] D58815: [clangd] Make sure constructors do not reference class

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 8 01:53:42 PST 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE355679: [clangd] Make sure constructors do not reference class (authored by kadircet, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D58815?vs=189832&id=189833#toc

Repository:
  rCTE Clang Tools Extra

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58815/new/

https://reviews.llvm.org/D58815

Files:
  clangd/XRefs.cpp
  clangd/index/SymbolCollector.cpp
  unittests/clangd/XRefsTests.cpp


Index: unittests/clangd/XRefsTests.cpp
===================================================================
--- unittests/clangd/XRefsTests.cpp
+++ unittests/clangd/XRefsTests.cpp
@@ -1337,6 +1337,15 @@
         }
       )cpp",
 
+      R"cpp(// Constructor
+        struct Foo {
+          [[F^oo]](int);
+        };
+        void foo() {
+          Foo f = [[Foo]](42);
+        }
+      )cpp",
+
       R"cpp(// Typedef
         typedef int [[Foo]];
         int main() {
Index: clangd/index/SymbolCollector.cpp
===================================================================
--- clangd/index/SymbolCollector.cpp
+++ clangd/index/SymbolCollector.cpp
@@ -211,7 +211,7 @@
 // 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<unsigned>(index::SymbolRole::Definition)) &&
          isa<TagDecl>(&ND) &&
          !SM.isWrittenInMainFile(SM.getExpansionLoc(ND.getLocation()));
@@ -305,6 +305,10 @@
        Decl::FriendObjectKind::FOK_None) &&
       !(Roles & static_cast<unsigned>(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<unsigned>(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
Index: clangd/XRefs.cpp
===================================================================
--- clangd/XRefs.cpp
+++ 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 @@
                       llvm::ArrayRef<index::SymbolRelation> Relations,
                       SourceLocation Loc,
                       index::IndexDataConsumer::ASTNodeInfo ASTNode) override {
+    // Skip non-semantic references.
+    if (Roles & static_cast<unsigned>(index::SymbolRole::NameReference))
+      return true;
+
     if (Loc == SearchedLocation) {
       auto IsImplicitExpr = [](const Expr *E) {
         if (!E)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58815.189833.patch
Type: text/x-patch
Size: 2601 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190308/a9221df5/attachment.bin>


More information about the cfe-commits mailing list