[PATCH] D111039: [clangd] Include refs of base method in refs for derived method.

Utkarsh Saxena via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 3 23:35:13 PDT 2021


usaxena95 created this revision.
usaxena95 added reviewers: hokein, kadircet.
Herald added a subscriber: arphaman.
usaxena95 requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Addresses https://github.com/clangd/clangd/issues/881

Includes refs of base class method in refs of derived class method.
Previously we reported base class method's refs only for decl of derived
class method. Ideally this should work for all usages of derived class method.

Related patch:
https://github.com/llvm/llvm-project/commit/fbeff2ec2bc6e44b92931207b0063f83ff7a3b3a.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D111039

Files:
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp


Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1978,7 +1978,7 @@
 }
 
 TEST(FindReferences, RefsToBaseMethod) {
-  llvm::StringRef Test =
+  const char *Tests[] = {
       R"cpp(
         class BaseBase {
         public:
@@ -1997,8 +1997,25 @@
           BB->[[func]]();
           B->[[func]]();
           D->[[func]]();
-        })cpp";
-  checkFindRefs(Test, /*UseIndex=*/true);
+        }
+      )cpp",
+      R"cpp(
+        class A {
+        public:
+          virtual void [[foo]]();
+        };
+        class B : public A {
+        public:
+          void $decl[[foo]]() override;
+        };
+        void test(A* a, B* b) {
+          a->[[foo]]();
+          b->[[fo^o]]();
+        }
+      )cpp",
+  };
+  for (const char *Test : Tests)
+    checkFindRefs(Test, /*UseIndex=*/true);
 }
 
 TEST(FindReferences, MainFileReferencesOnly) {
Index: clang-tools-extra/clangd/XRefs.cpp
===================================================================
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -1392,10 +1392,8 @@
         // references to all overridden methods in complete type hierarchy.
         if (const auto *CMD = llvm::dyn_cast<CXXMethodDecl>(ND)) {
           if (CMD->isVirtual())
-            if (IdentifierAtCursor && SM.getSpellingLoc(CMD->getLocation()) ==
-                                          IdentifierAtCursor->location()) {
-              if (auto ID = getSymbolID(CMD))
-                OverriddenBy.Subjects.insert(ID);
+            if (auto ID = getSymbolID(CMD)) {
+              OverriddenBy.Subjects.insert(ID);
               getOverriddenMethods(CMD, OverriddenMethods);
             }
         }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111039.376810.patch
Type: text/x-patch
Size: 1870 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211004/5dea8a2f/attachment-0001.bin>


More information about the cfe-commits mailing list