[clang-tools-extra] 4c430a7 - [clangd] Do not report anonymous entities in findExplicitReferences

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 28 06:45:59 PDT 2019


Author: Ilya Biryukov
Date: 2019-10-28T14:41:34+01:00
New Revision: 4c430a7c6f6b11105963c6a0ff1e6ee31517a1c8

URL: https://github.com/llvm/llvm-project/commit/4c430a7c6f6b11105963c6a0ff1e6ee31517a1c8
DIFF: https://github.com/llvm/llvm-project/commit/4c430a7c6f6b11105963c6a0ff1e6ee31517a1c8.diff

LOG: [clangd] Do not report anonymous entities in findExplicitReferences

Summary:
Otherwise every client dealing with name location should handle
anonymous names in a special manner.

This seems too error-prone, clients can probably handle anonymous
entities they care about differently.

Reviewers: hokein

Reviewed By: hokein

Subscribers: MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69511

Added: 
    

Modified: 
    clang-tools-extra/clangd/FindTarget.cpp
    clang-tools-extra/clangd/unittests/FindTargetTests.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/FindTarget.cpp b/clang-tools-extra/clangd/FindTarget.cpp
index 7dc7fd906be9..1ab80b72a90b 100644
--- a/clang-tools-extra/clangd/FindTarget.cpp
+++ b/clang-tools-extra/clangd/FindTarget.cpp
@@ -448,8 +448,15 @@ llvm::SmallVector<ReferenceLoc, 2> refInDecl(const Decl *D) {
       // FIXME: decide on how to surface destructors when we need them.
       if (llvm::isa<CXXDestructorDecl>(ND))
         return;
-      Refs.push_back(ReferenceLoc{
-          getQualifierLoc(*ND), ND->getLocation(), /*IsDecl=*/true, {ND}});
+      // Filter anonymous decls, name location will point outside the name token
+      // and the clients are not prepared to handle that.
+      if (ND->getDeclName().isIdentifier() &&
+          !ND->getDeclName().getAsIdentifierInfo())
+        return;
+      Refs.push_back(ReferenceLoc{getQualifierLoc(*ND),
+                                  ND->getLocation(),
+                                  /*IsDecl=*/true,
+                                  {ND}});
     }
   };
 

diff  --git a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
index f7095aebd868..6b0e51b228b8 100644
--- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -852,8 +852,8 @@ TEST_F(FindExplicitReferencesTest, All) {
                };
                // delegating initializer
                class $10^Foo {
-                 $11^Foo(int$12^);
-                 $13^Foo(): $14^Foo(111) {}
+                 $11^Foo(int);
+                 $12^Foo(): $13^Foo(111) {}
                };
              }
            )cpp",
@@ -869,11 +869,19 @@ TEST_F(FindExplicitReferencesTest, All) {
            "9: targets = {Base}\n"
            "10: targets = {Foo}, decl\n"
            "11: targets = {foo()::Foo::Foo}, decl\n"
-           // FIXME: we should exclude the built-in type.
-           "12: targets = {}, decl\n"
-           "13: targets = {foo()::Foo::Foo}, decl\n"
-           "14: targets = {Foo}\n"},
-
+           "12: targets = {foo()::Foo::Foo}, decl\n"
+           "13: targets = {Foo}\n"},
+          // Anonymous entities should not be reported.
+          {
+              R"cpp(
+             void foo() {
+              class {} $0^x;
+              int (*$1^fptr)(int $2^a, int) = nullptr;
+             }
+           )cpp",
+              "0: targets = {x}, decl\n"
+              "1: targets = {fptr}, decl\n"
+              "2: targets = {a}, decl\n"},
       };
 
   for (const auto &C : Cases) {


        


More information about the cfe-commits mailing list