This is an archive of the discontinued LLVM Phabricator instance.

[include-cleaner] Don't count references to operators as uses
ClosedPublic

Authored by hokein on Dec 22 2022, 6:31 AM.

Diff Detail

Event Timeline

hokein created this revision.Dec 22 2022, 6:31 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 22 2022, 6:31 AM
Herald added a subscriber: kadircet. · View Herald Transcript
hokein requested review of this revision.Dec 22 2022, 6:31 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 22 2022, 6:31 AM

Yeah, I think this makes sense.
I think this sort of thing should ideally be captured in the include-cleaner design doc if there was one. (Doesn't make sense to create one just for this issue, but it seems like a doc that should exist).

clang-tools-extra/include-cleaner/lib/WalkAST.cpp
69

Rather than override TraverseCXXOperatorCallExpr to do everything *except* call WalkUpFrom, maybe override WalkUpFromCXXOperatorCallExpr to call VisitCXXOperatorCallExpr but not WalkUpFromCallExpr? (With a comment that we don't want to treat operators as calls)

71

maybe motivate this a little: (generally the type should provide them)

hokein updated this revision to Diff 487382.Jan 9 2023, 4:33 AM
hokein marked an inline comment as done.

update

clang-tools-extra/include-cleaner/lib/WalkAST.cpp
69

Rather than override TraverseCXXOperatorCallExpr to do everything *except* call WalkUpFrom.

Ah, not really (it is my fault that I missed to call WalkUpFrom, but it is not the key point) .
The key point is to traverse every child of CXXOperatorCallExpr *except* the operator. E.g. for the AST node below, we don't want to traverse its first child which is the operator.

-CXXOperatorCallExpr 0x5591a97f5280 <col:9, col:27> 'int' '+'
    |-ImplicitCastExpr 0x5591a97f5268 <col:18> 'int (*)(string, string)' <FunctionToPointerDecay>
    | `-DeclRefExpr 0x5591a97f51e8 <col:18> 'int (string, string)' lvalue Function 0x5591a97f4878 'operator+' 'int (string, string)'
    |-CXXTemporaryObjectExpr 0x5591a97f5068 <col:9, col:16> 'string':'string' 'void () noexcept' zeroing
    `-CXXTemporaryObjectExpr 0x5591a97f51b8 <col:20, col:27>

I added the WalkUpFromCXXOperatorCallExpr back (I think it doesn't have any effect on the current code because we don't do anything on the CXXOperatorCallExpr hierarchy classes).

sammccall accepted this revision.Jan 9 2023, 4:40 AM
sammccall added inline comments.
clang-tools-extra/include-cleaner/lib/WalkAST.cpp
69

Yeah, sorry I was confused and thought we handled function refs in CallExpr instead of DeclRefExpr

75

This comment doesn't mention the callee at all, and the callee is the point.

Maybe: "Don't traverse the callee." and add a newline before the arguments() loop?
(because this comment isn't really related to that part, arguments() is just part of the "everything else" that we're still doing)

This revision is now accepted and ready to land.Jan 9 2023, 4:40 AM
This revision was landed with ongoing or failed builds.Jan 9 2023, 5:03 AM
This revision was automatically updated to reflect the committed changes.