diff options
author | Shuai Wang <shuaiwang@google.com> | 2018-09-17 20:10:56 +0000 |
---|---|---|
committer | Shuai Wang <shuaiwang@google.com> | 2018-09-17 20:10:56 +0000 |
commit | 4305993c89defbb7b5dda2685cf92e1d5512dd23 (patch) | |
tree | 6d76a9fb44a632a3561379387bf22e5baeb3fdb0 /clang/lib | |
parent | 02bfd89c9310648b949807ea8021a816ae64ee08 (diff) | |
download | bcm5719-llvm-4305993c89defbb7b5dda2685cf92e1d5512dd23.tar.gz bcm5719-llvm-4305993c89defbb7b5dda2685cf92e1d5512dd23.zip |
[analyzer] Treat std::{move,forward} as casts in ExprMutationAnalyzer.
Summary:
This is a follow up of D52008 and should make the analyzer being able to handle perfect forwardings in real world cases where forwardings are done through multiple layers of function calls with `std::forward`.
Fixes PR38891.
Reviewers: lebedev.ri, JonasToth, george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin, mikhail.ramalho, Szelethus, cfe-commits
Differential Revision: https://reviews.llvm.org/D52120
llvm-svn: 342409
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Analysis/ExprMutationAnalyzer.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/clang/lib/Analysis/ExprMutationAnalyzer.cpp b/clang/lib/Analysis/ExprMutationAnalyzer.cpp index 50d4d0b8890..db8c259a52a 100644 --- a/clang/lib/Analysis/ExprMutationAnalyzer.cpp +++ b/clang/lib/Analysis/ExprMutationAnalyzer.cpp @@ -304,7 +304,16 @@ const Stmt *ExprMutationAnalyzer::findCastMutation(const Expr *Exp) { nonConstReferenceType())))) .bind(NodeID<Expr>::value)), Stm, Context); - return findExprMutation(Casts); + if (const Stmt *S = findExprMutation(Casts)) + return S; + // Treat std::{move,forward} as cast. + const auto Calls = + match(findAll(callExpr(callee(namedDecl( + hasAnyName("::std::move", "::std::forward"))), + hasArgument(0, equalsNode(Exp))) + .bind("expr")), + Stm, Context); + return findExprMutation(Calls); } const Stmt *ExprMutationAnalyzer::findRangeLoopMutation(const Expr *Exp) { @@ -360,7 +369,9 @@ const Stmt *ExprMutationAnalyzer::findFunctionArgMutation(const Expr *Exp) { const auto IsInstantiated = hasDeclaration(isInstantiated()); const auto FuncDecl = hasDeclaration(functionDecl().bind("func")); const auto Matches = match( - findAll(expr(anyOf(callExpr(NonConstRefParam, IsInstantiated, FuncDecl), + findAll(expr(anyOf(callExpr(NonConstRefParam, IsInstantiated, FuncDecl, + unless(callee(namedDecl(hasAnyName( + "::std::move", "::std::forward"))))), cxxConstructExpr(NonConstRefParam, IsInstantiated, FuncDecl))) .bind(NodeID<Expr>::value)), |