]> granicus.if.org Git - clang/commit
[analyzer] Handle forwarding reference better in ExprMutationAnalyzer.
authorShuai Wang <shuaiwang@google.com>
Fri, 14 Sep 2018 20:07:18 +0000 (20:07 +0000)
committerShuai Wang <shuaiwang@google.com>
Fri, 14 Sep 2018 20:07:18 +0000 (20:07 +0000)
commit2530891b27d48e6e2b153e0f59ea286afdbc2200
tree9e412776e652d049fcccccba10a4d28a6ad53b66
parentccd349c348ad7930306dfc07c49e74c83d3f40bb
[analyzer] Handle forwarding reference better in ExprMutationAnalyzer.

Summary:
We used to treat an `Expr` mutated whenever it's passed as non-const
reference argument to a function. This results in false positives in
cases like this:
```
int x;
std::vector<int> v;
v.emplace_back(x); // `x` is passed as non-const reference to `emplace_back`
```
In theory the false positives can be suppressed with
`v.emplace_back(std::as_const(x))` but that's considered overly verbose,
inconsistent with existing code and spammy as diags.

This diff handles such cases by following into the function definition
and see whether the argument is mutated inside.

Reviewers: lebedev.ri, JonasToth, george.karpenkov

Subscribers: xazax.hun, szepet, a.sidorin, mikhail.ramalho, Szelethus, cfe-commits

Differential Revision: https://reviews.llvm.org/D52008

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@342271 91177308-0d34-0410-b5e6-96231b3b80d8
include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
lib/Analysis/ExprMutationAnalyzer.cpp
unittests/Analysis/ExprMutationAnalyzerTest.cpp