This is an archive of the discontinued LLVM Phabricator instance.

[IncludeCleaner] Handle more C++ constructs
ClosedPublic

Authored by kadircet on Aug 18 2022, 1:24 AM.

Details

Summary

This brings IncludeCleaner's reference discovery from AST to the parity
with current implementation in clangd. Some highlights:

  • Handling of MemberExprs, only the member declaration is marked as referenced and not the container, unlike clangd.
  • Constructor calls, only the constructor and not the container, unlike clangd.
  • All the possible candidates for unresolved overloads, same as clangd.
  • All the shadow decls for using-decls, same as clangd.
  • Declarations for definitions of enums with an underlying type and functions, same as clangd.
  • Using typelocs, using templatenames and typedefs only reference the found decl, same as clangd.
  • Template specializations only reference the primary template, not the explicit specializations, to be fixed.
  • Expr types aren't marked as used, unlike clangd.

Going forward, we can consider having signals to indicate type of a
reference (e.g. implicit signal for type of an expr) so that the
applications can perform a filtering based on their needs.
At the moment the biggest discrepancy is around type of exprs, i.e. not
marking containers for member/constructor accesses. I believe this is
the right model since the declaration of the member and the container
should be available in a single file (modulo macros).

Diff Detail

Event Timeline

kadircet created this revision.Aug 18 2022, 1:24 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 18 2022, 1:24 AM
kadircet requested review of this revision.Aug 18 2022, 1:24 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 18 2022, 1:24 AM
sammccall added inline comments.Aug 18 2022, 2:22 AM
clang-tools-extra/include-cleaner/lib/WalkAST.cpp
55

nit: inline?

55

should this be the founddecl instead of the memberdecl?

66

I think we need a policy knob for this, to decide whether to over or underestimate.
This would be the wrong behavior for missing-includes analysis.

66

comment echoes the code, say why instead

72

I wonder if this is correct enough.

This brings a set of overloads into scope, the intention may be to bring a particular overload with others as harmless side effects: consider using std::swap.
In this case, inserting includes for all the overloads that happened to be visible would be too much.

Possible behaviors:

  • what we do here
  • only do this if overestimate=true
  • if overestimate=false, only include those USDs marked as referenced (not sure if they actually get marked appropriately, the bit exists)
79

comment echoes the code, say why instead

110

nit: *explicit* specializations?

kadircet updated this revision to Diff 453638.Aug 18 2022, 5:52 AM
kadircet marked 5 inline comments as done.
  • Adress comments
clang-tools-extra/include-cleaner/lib/WalkAST.cpp
55

right, forgot about these. also added a test.

66

i agree that this needs a knob. it's just unclear at which level currently, i am putting together a doc to have a better decision here (mostly to post vs pre filter).

i'd rather move forward with this version, to prepare grounds for the tidy check and clangd usage based on this library, and address these issues in a new iteration.

72

i agree, basically the same things as I mentioned above, we should definitely have a way to filter these.

sammccall accepted this revision.Aug 19 2022, 3:39 AM
sammccall added inline comments.
clang-tools-extra/include-cleaner/lib/WalkAST.cpp
66

OK, add a FIXME?

72

ack, again let's mark this as incomplete somehow (esp because this one is subtle)

This revision is now accepted and ready to land.Aug 19 2022, 3:39 AM
kadircet updated this revision to Diff 470393.Oct 25 2022, 12:58 AM
kadircet marked 4 inline comments as done.
  • Rebase
  • Add FIXMEs
This revision was landed with ongoing or failed builds.Oct 25 2022, 12:59 AM
This revision was automatically updated to reflect the committed changes.