Index: clang-tidy/performance/ForRangeCopyCheck.cpp =================================================================== --- clang-tidy/performance/ForRangeCopyCheck.cpp +++ clang-tidy/performance/ForRangeCopyCheck.cpp @@ -88,8 +88,8 @@ // Because the fix (changing to `const auto &`) will introduce an unused // compiler warning which can't be suppressed. // Since this case is very rare, it is safe to ignore it. - if (!utils::ExprMutationAnalyzer(ForRange.getBody(), &Context) - .isMutated(&LoopVar) && + if (!utils::ExprMutationAnalyzer(*ForRange.getBody(), Context) + .isMutated(&LoopVar) && !utils::decl_ref_expr::allDeclRefExprs(LoopVar, *ForRange.getBody(), Context) .empty()) { Index: clang-tidy/performance/UnnecessaryValueParamCheck.cpp =================================================================== --- clang-tidy/performance/UnnecessaryValueParamCheck.cpp +++ clang-tidy/performance/UnnecessaryValueParamCheck.cpp @@ -95,14 +95,14 @@ // Do not trigger on non-const value parameters when they are mutated either // within the function body or within init expression(s) when the function is // a ctor. - if (utils::ExprMutationAnalyzer(Function->getBody(), Result.Context) + if (utils::ExprMutationAnalyzer(*Function->getBody(), *Result.Context) .isMutated(Param)) return; // CXXCtorInitializer might also mutate Param but they're not part of function // body, so check them separately here. if (const auto *Ctor = dyn_cast(Function)) { for (const auto *Init : Ctor->inits()) { - if (utils::ExprMutationAnalyzer(Init->getInit(), Result.Context) + if (utils::ExprMutationAnalyzer(*Init->getInit(), *Result.Context) .isMutated(Param)) return; } Index: clang-tidy/utils/ExprMutationAnalyzer.h =================================================================== --- clang-tidy/utils/ExprMutationAnalyzer.h +++ clang-tidy/utils/ExprMutationAnalyzer.h @@ -23,7 +23,7 @@ /// a given statement. class ExprMutationAnalyzer { public: - ExprMutationAnalyzer(const Stmt *Stm, ASTContext *Context) + ExprMutationAnalyzer(const Stmt &Stm, ASTContext &Context) : Stm(Stm), Context(Context) {} bool isMutated(const Decl *Dec) { return findDeclMutation(Dec) != nullptr; } @@ -44,8 +44,8 @@ const Stmt *findRangeLoopMutation(const Expr *Exp); const Stmt *findReferenceMutation(const Expr *Exp); - const Stmt *const Stm; - ASTContext *const Context; + const Stmt &Stm; + ASTContext &Context; llvm::DenseMap Results; }; Index: clang-tidy/utils/ExprMutationAnalyzer.cpp =================================================================== --- clang-tidy/utils/ExprMutationAnalyzer.cpp +++ clang-tidy/utils/ExprMutationAnalyzer.cpp @@ -102,7 +102,7 @@ hasDescendant(equalsNode(Exp)))), cxxNoexceptExpr()))))) .bind("expr")), - *Stm, *Context)) != nullptr; + Stm, Context)) != nullptr; } const Stmt * @@ -125,7 +125,7 @@ const Stmt *ExprMutationAnalyzer::findDeclMutation(const Decl *Dec) { const auto Refs = match( - findAll(declRefExpr(to(equalsNode(Dec))).bind("expr")), *Stm, *Context); + findAll(declRefExpr(to(equalsNode(Dec))).bind("expr")), Stm, Context); for (const auto &RefNodes : Refs) { const auto *E = RefNodes.getNodeAs("expr"); if (findMutation(E)) @@ -200,18 +200,15 @@ AsNonConstRefArg, AsLambdaRefCaptureInit, AsNonConstRefReturn)) .bind("stmt")), - *Stm, *Context); + Stm, Context); return selectFirst("stmt", Matches); } const Stmt *ExprMutationAnalyzer::findMemberMutation(const Expr *Exp) { // Check whether any member of 'Exp' is mutated. - const auto MemberExprs = - match(findAll(expr(anyOf(memberExpr(hasObjectExpression(equalsNode(Exp))), - cxxDependentScopeMemberExpr( - hasObjectExpression(equalsNode(Exp))))) - .bind("expr")), - *Stm, *Context); + const auto MemberExprs = match( + findAll(memberExpr(hasObjectExpression(equalsNode(Exp))).bind("expr")), + Stm, Context); return findExprMutation(MemberExprs); } @@ -220,7 +217,7 @@ const auto SubscriptExprs = match( findAll(arraySubscriptExpr(hasBase(ignoringImpCasts(equalsNode(Exp)))) .bind("expr")), - *Stm, *Context); + Stm, Context); return findExprMutation(SubscriptExprs); } @@ -233,7 +230,7 @@ implicitCastExpr(hasImplicitDestinationType( nonConstReferenceType())))) .bind("expr")), - *Stm, *Context); + Stm, Context); return findExprMutation(Casts); } @@ -245,7 +242,7 @@ hasLoopVariable( varDecl(hasType(nonConstReferenceType())).bind("decl")), hasRangeInit(equalsNode(Exp)))), - *Stm, *Context); + Stm, Context); return findDeclMutation(LoopVars); } @@ -265,7 +262,7 @@ unless(hasParent(declStmt(hasParent( cxxForRangeStmt(hasRangeStmt(equalsBoundNode("stmt")))))))) .bind("decl"))), - *Stm, *Context); + Stm, Context); return findDeclMutation(Refs); } Index: unittests/clang-tidy/ExprMutationAnalyzerTest.cpp =================================================================== --- unittests/clang-tidy/ExprMutationAnalyzerTest.cpp +++ unittests/clang-tidy/ExprMutationAnalyzerTest.cpp @@ -42,14 +42,14 @@ bool isMutated(const SmallVectorImpl &Results, ASTUnit *AST) { const auto *const S = selectFirst("stmt", Results); const auto *const E = selectFirst("expr", Results); - return utils::ExprMutationAnalyzer(S, &AST->getASTContext()).isMutated(E); + return utils::ExprMutationAnalyzer(*S, AST->getASTContext()).isMutated(E); } SmallVector mutatedBy(const SmallVectorImpl &Results, ASTUnit *AST) { const auto *const S = selectFirst("stmt", Results); SmallVector Chain; - utils::ExprMutationAnalyzer Analyzer(S, &AST->getASTContext()); + utils::ExprMutationAnalyzer Analyzer(*S, AST->getASTContext()); for (const auto *E = selectFirst("expr", Results); E != nullptr;) { const Stmt *By = Analyzer.findMutation(E); std::string buffer;