summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/utils/ExprMutationAnalyzer.cpp
diff options
context:
space:
mode:
authorShuai Wang <shuaiwang@google.com>2018-09-10 18:05:13 +0000
committerShuai Wang <shuaiwang@google.com>2018-09-10 18:05:13 +0000
commitbef0941b6b4b01374f24d5d0d3155826e015c231 (patch)
tree4b4a3857435f3e434ef29ccf96423c736818443a /clang-tools-extra/clang-tidy/utils/ExprMutationAnalyzer.cpp
parentf8acd723e83ed681ac46235eb6bed9d6d429bdd4 (diff)
downloadbcm5719-llvm-bef0941b6b4b01374f24d5d0d3155826e015c231.tar.gz
bcm5719-llvm-bef0941b6b4b01374f24d5d0d3155826e015c231.zip
[clang-tidy] Handle unresolved expressions in ExprMutationAnalyzer
Summary: - If a function is unresolved, assume it mutates its arguments - Follow unresolved member expressions for nested mutations Reviewers: aaron.ballman, JonasToth, george.karpenkov Subscribers: xazax.hun, a.sidorin, cfe-commits Differential Revision: https://reviews.llvm.org/D50619 llvm-svn: 341848
Diffstat (limited to 'clang-tools-extra/clang-tidy/utils/ExprMutationAnalyzer.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/utils/ExprMutationAnalyzer.cpp26
1 files changed, 20 insertions, 6 deletions
diff --git a/clang-tools-extra/clang-tidy/utils/ExprMutationAnalyzer.cpp b/clang-tools-extra/clang-tidy/utils/ExprMutationAnalyzer.cpp
index 424fa8f672e..f1cd1daf577 100644
--- a/clang-tools-extra/clang-tidy/utils/ExprMutationAnalyzer.cpp
+++ b/clang-tools-extra/clang-tidy/utils/ExprMutationAnalyzer.cpp
@@ -145,11 +145,16 @@ const Stmt *ExprMutationAnalyzer::findDirectMutation(const Expr *Exp) {
hasUnaryOperand(equalsNode(Exp)));
// Invoking non-const member function.
+ // A member function is assumed to be non-const when it is unresolved.
const auto NonConstMethod = cxxMethodDecl(unless(isConst()));
const auto AsNonConstThis =
expr(anyOf(cxxMemberCallExpr(callee(NonConstMethod), on(equalsNode(Exp))),
cxxOperatorCallExpr(callee(NonConstMethod),
- hasArgument(0, equalsNode(Exp)))));
+ hasArgument(0, equalsNode(Exp))),
+ callExpr(callee(expr(anyOf(
+ unresolvedMemberExpr(hasObjectExpression(equalsNode(Exp))),
+ cxxDependentScopeMemberExpr(
+ hasObjectExpression(equalsNode(Exp)))))))));
// Taking address of 'Exp'.
// We're assuming 'Exp' is mutated as soon as its address is taken, though in
@@ -165,10 +170,16 @@ const Stmt *ExprMutationAnalyzer::findDirectMutation(const Expr *Exp) {
unless(hasParent(arraySubscriptExpr())), has(equalsNode(Exp)));
// Used as non-const-ref argument when calling a function.
+ // An argument is assumed to be non-const-ref when the function is unresolved.
const auto NonConstRefParam = forEachArgumentWithParam(
equalsNode(Exp), parmVarDecl(hasType(nonConstReferenceType())));
- const auto AsNonConstRefArg =
- anyOf(callExpr(NonConstRefParam), cxxConstructExpr(NonConstRefParam));
+ const auto AsNonConstRefArg = anyOf(
+ callExpr(NonConstRefParam), cxxConstructExpr(NonConstRefParam),
+ callExpr(callee(expr(anyOf(unresolvedLookupExpr(), unresolvedMemberExpr(),
+ cxxDependentScopeMemberExpr(),
+ hasType(templateTypeParmType())))),
+ hasAnyArgument(equalsNode(Exp))),
+ cxxUnresolvedConstructExpr(hasAnyArgument(equalsNode(Exp))));
// Captured by a lambda by reference.
// If we're initializing a capture with 'Exp' directly then we're initializing
@@ -195,9 +206,12 @@ const Stmt *ExprMutationAnalyzer::findDirectMutation(const Expr *Exp) {
const Stmt *ExprMutationAnalyzer::findMemberMutation(const Expr *Exp) {
// Check whether any member of 'Exp' is mutated.
- const auto MemberExprs = match(
- findAll(memberExpr(hasObjectExpression(equalsNode(Exp))).bind("expr")),
- *Stm, *Context);
+ const auto MemberExprs =
+ match(findAll(expr(anyOf(memberExpr(hasObjectExpression(equalsNode(Exp))),
+ cxxDependentScopeMemberExpr(
+ hasObjectExpression(equalsNode(Exp)))))
+ .bind("expr")),
+ *Stm, *Context);
return findExprMutation(MemberExprs);
}
OpenPOWER on IntegriCloud