This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Report xref for base methods.
ClosedPublic

Authored by usaxena95 on Feb 2 2021, 12:06 AM.

Details

Summary

See: https://github.com/clangd/clangd/issues/668

struct A { virtual void foo() = 0; };
struct B : A { void foo() override; };

Find refs on B::foo() will show:

  • decls of A::foo() (new)
  • decls of B::foo()
  • refs to A::foo() (new)
  • refs to B::foo().

Diff Detail

Event Timeline

usaxena95 created this revision.Feb 2 2021, 12:06 AM
usaxena95 requested review of this revision.Feb 2 2021, 12:06 AM
hokein added inline comments.Feb 2 2021, 1:34 AM
clang-tools-extra/clangd/unittests/XRefsTests.cpp
1902

ah, this is a good case! I think we should include the base's base method as part of the refs -- because BB->func() can actually call D::func if BB points to a Derived object.

the fix is to add ids from overridden_methods recursively.

usaxena95 added inline comments.Feb 2 2021, 6:40 AM
clang-tools-extra/clangd/unittests/XRefsTests.cpp
1902

Yeah we can do that. Although I had intentionally left those out considering the number of references would increase significantly if we do it for the complete type hierarchy. Also since LSP doesn't provide a way to annotate these kind of references, it would be hard for users to find exact refs (to Derived::foo()).
WDYT ?

usaxena95 updated this revision to Diff 321038.Feb 3 2021, 2:29 AM

Addressed comments.

usaxena95 marked an inline comment as done.Feb 3 2021, 2:33 AM
hokein accepted this revision.Feb 3 2021, 2:38 AM

Thanks!

clang-tools-extra/clangd/XRefs.cpp
1294

The recursive will be infinite if we have a cycle, but I guess clang will never generate a broken AST like that.

This revision is now accepted and ready to land.Feb 3 2021, 2:38 AM
This revision was landed with ongoing or failed builds.Feb 3 2021, 3:08 AM
This revision was automatically updated to reflect the committed changes.