llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.1k stars 11.6k forks source link

unify detection of object mutation in clang-tidy checks #106374

Open firewave opened 3 weeks ago

firewave commented 3 weeks ago

Weirdly, those two checks are using distinct methods to infer whether the underlying container is mutated. unnecessary-copy-initialization uses doesNotMutateObject while performance-unnecessary-value-param uses FunctionParmMutationAnalyzer.

So unfortunately this change won't improve performance-unnecessary-value-param.

I can have a look at unifying both in a subsequent PR.

Originally posted by @legrosbuffle in https://github.com/llvm/llvm-project/issues/94362#issuecomment-2149113119

HerrCai0907 commented 4 days ago

I think the target of two functions is totally different. isOnlyUsedAsConst want to detect the usage of object itself. MutationAnalyzer want to detect mutation of the symbol of this object.

e.g. For symbol a, a = A{}, isOnlyUsedAsConst should not treat it as non-const usage but MutationAnalyzer should treat it as mutation.