[clang-tools-extra] [clang-tidy] Add performance-redundant-lookup check (PR #125420)
Balazs Benics via cfe-commits
cfe-commits at lists.llvm.org
Sat Feb 8 08:04:52 PST 2025
steakhal wrote:
I revisited the check using `ExprSequence`.
It became more actionable from what I can tell, but exposes weaknesses of `ExprSequence` too, which I'll later demonstrate.
My approach with my prototype using `ExprSequence` was:
1) Collect lookups just like before.
2) Take the cross product of the lookups, and build a graph using the `inSequence` relationship among the lookups.
3) Take the nodes that has no parents, aka. roots of the `inSequence` graph, because I'll report a separate "bug" for the reachable lookups from each Root.
4) Pick the last lookup of the group as the diagnostic location, and add notes for the rest.
This got fairly involved, and likely scales really poorly with the number of lookups using the same key and container.
The results are mixed, and I think it's caused by `ExprSequence`, and hallucinates `inSequence` relationship for Stmt pairs where it actually shouldn't.
Here are a couple of examples:



So, if `ExprSequence` would honor `return` statements and if blocks, then it would be a viable direction to move forward.
https://github.com/llvm/llvm-project/pull/125420
More information about the cfe-commits
mailing list