Author: shuaiwang Date: Sat Sep 15 14:38:18 2018 New Revision: 342340 URL: http://llvm.org/viewvc/llvm-project?rev=342340&view=rev Log: [NFC] cosmetic tweaks to ExprMutationAnalyzer to be more consistent especially considering future changes.
Modified: cfe/trunk/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h cfe/trunk/lib/Analysis/ExprMutationAnalyzer.cpp Modified: cfe/trunk/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h?rev=342340&r1=342339&r2=342340&view=diff ============================================================================== --- cfe/trunk/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h (original) +++ cfe/trunk/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h Sat Sep 15 14:38:18 2018 @@ -26,12 +26,14 @@ public: ExprMutationAnalyzer(const Stmt &Stm, ASTContext &Context) : Stm(Stm), Context(Context) {} - bool isMutated(const Decl *Dec) { return findDeclMutation(Dec) != nullptr; } bool isMutated(const Expr *Exp) { return findMutation(Exp) != nullptr; } + bool isMutated(const Decl *Dec) { return findMutation(Dec) != nullptr; } const Stmt *findMutation(const Expr *Exp); - const Stmt *findDeclMutation(const Decl *Dec); + const Stmt *findMutation(const Decl *Dec); private: + using ResultMap = llvm::DenseMap<const Expr *, const Stmt *>; + bool isUnevaluated(const Expr *Exp); const Stmt *findExprMutation(ArrayRef<ast_matchers::BoundNodes> Matches); @@ -50,7 +52,7 @@ private: llvm::DenseMap<const FunctionDecl *, std::unique_ptr<FunctionParmMutationAnalyzer>> FuncParmAnalyzer; - llvm::DenseMap<const Expr *, const Stmt *> Results; + ResultMap Results; }; // A convenient wrapper around ExprMutationAnalyzer for analyzing function Modified: cfe/trunk/lib/Analysis/ExprMutationAnalyzer.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ExprMutationAnalyzer.cpp?rev=342340&r1=342339&r2=342340&view=diff ============================================================================== --- cfe/trunk/lib/Analysis/ExprMutationAnalyzer.cpp (original) +++ cfe/trunk/lib/Analysis/ExprMutationAnalyzer.cpp Sat Sep 15 14:38:18 2018 @@ -131,13 +131,13 @@ ExprMutationAnalyzer::findExprMutation(A const Stmt * ExprMutationAnalyzer::findDeclMutation(ArrayRef<BoundNodes> Matches) { for (const auto &DeclNodes : Matches) { - if (const Stmt *S = findDeclMutation(DeclNodes.getNodeAs<Decl>("decl"))) + if (const Stmt *S = findMutation(DeclNodes.getNodeAs<Decl>("decl"))) return S; } return nullptr; } -const Stmt *ExprMutationAnalyzer::findDeclMutation(const Decl *Dec) { +const Stmt *ExprMutationAnalyzer::findMutation(const Decl *Dec) { const auto Refs = match( findAll(declRefExpr(to(equalsNode(Dec))).bind("expr")), Stm, Context); for (const auto &RefNodes : Refs) { @@ -280,15 +280,14 @@ const Stmt *ExprMutationAnalyzer::findRe // Follow non-const reference returned by `operator*()` of move-only classes. // These are typically smart pointers with unique ownership so we treat // mutation of pointee as mutation of the smart pointer itself. - const auto Ref = match( - findAll(cxxOperatorCallExpr( - hasOverloadedOperatorName("*"), - callee(cxxMethodDecl(ofClass(isMoveOnly()), - returns(hasUnqualifiedDesugaredType( - nonConstReferenceType())))), - argumentCountIs(1), hasArgument(0, equalsNode(Exp))) - .bind("expr")), - Stm, Context); + const auto Ref = + match(findAll(cxxOperatorCallExpr( + hasOverloadedOperatorName("*"), + callee(cxxMethodDecl(ofClass(isMoveOnly()), + returns(nonConstReferenceType()))), + argumentCountIs(1), hasArgument(0, equalsNode(Exp))) + .bind("expr")), + Stm, Context); if (const Stmt *S = findExprMutation(Ref)) return S; @@ -370,7 +369,7 @@ FunctionParmMutationAnalyzer::FunctionPa for (const ParmVarDecl *Parm : Ctor->parameters()) { if (Results.find(Parm) != Results.end()) continue; - if (const Stmt *S = InitAnalyzer.findDeclMutation(Parm)) + if (const Stmt *S = InitAnalyzer.findMutation(Parm)) Results[Parm] = S; } } @@ -383,7 +382,7 @@ FunctionParmMutationAnalyzer::findMutati if (Memoized != Results.end()) return Memoized->second; - if (const Stmt *S = BodyAnalyzer.findDeclMutation(Parm)) + if (const Stmt *S = BodyAnalyzer.findMutation(Parm)) return Results[Parm] = S; return Results[Parm] = nullptr; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits