[clang] [clang-tools-extra] [clang-tidy] Fix performance-unnecessary-value-param (PR #109145)

Kazu Hirata via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 18 10:23:39 PDT 2024


================

----------------
kazutakahirata wrote:

I cannot immediately think of common ways in which an iterator stays valid, but if you don't enable assertions or `LLVM_ENABLE_ABI_BREAKING_CHECKS`, you may be able to avoid a crash although that doesn't necessarily mean that clang-tidy is working correctly.

If you would like a more reliable way to detect potential iterator invalidation, you could check the size of the data structure before and after calling `new FunctionParmMutationAnalyzer(...)`:

```
auto OldSize = Memorized.FuncParmAnalyzer.size();
NewValue = std::unique_ptr<FunctionParmMutationAnalyzer>(
  new FunctionParmMutationAnalyzer(Func, Context, Memorized));
auto NewSize = Memorized.FuncParmAnalyzer.size();
assert(OldSize == NewSize);
it->second = NewValue;
```


https://github.com/llvm/llvm-project/pull/109145


More information about the cfe-commits mailing list