[PATCH] D103087: [clang-tidy] performances-unnecessary-* checks: Extend isOnlyUsedAsConst to expressions and catch const methods returning non-const references/pointers.

Felix Berger via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 11 11:21:09 PDT 2021


flx added a comment.

In D103087#2793673 <https://reviews.llvm.org/D103087#2793673>, @ymandel wrote:

> I have some concerns about the cost of this checks as it used matching over entire contexts quite extensively.  At this point, the facilities involved seem quite close to doing dataflow analysis and I wonder if you might be better off with a very different implementation. Regardless, have you done any perfomance testing to see the impact on real code?

That's a fair point. Is there prior art in terms of dataflow analysis in ClangTidy or LLVM I could take a look at?

In terms of measuring performance, do you have suggestions how to measure this? I can add a counter that counts the recursion depth that is reached to see how often this happens in practice.

Another idea is to not count const methods from returning mutable pointer or reference types as const access. Standard types std::vector and absl::StatusOr would not be affected by this restriction, their const accessors return const references as well.

I'll hold off on this change until I see more false positives.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103087/new/

https://reviews.llvm.org/D103087



More information about the cfe-commits mailing list