From bfacf17b8b99f2c6d51bf570a11d6e6a5d3a2a39 Mon Sep 17 00:00:00 2001 From: Anna Zaks Date: Mon, 1 Oct 2012 20:33:58 +0000 Subject: [PATCH] [analyzer] Address Jordan's review for r164868. llvm-svn: 164965 --- .../Checkers/IvarInvalidationChecker.cpp | 30 ++++++++++------------ 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp index e269f46..5f94403 100644 --- a/clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp @@ -111,7 +111,9 @@ class IvarInvalidationChecker : /// The invalidation method being currently processed. const ObjCMethodDecl *InvalidationMethod; - /// Peel off parents, casts, OpaqueValueExpr, and PseudoObjectExpr. + ASTContext &Ctx; + + /// Peel off parens, casts, OpaqueValueExpr, and PseudoObjectExpr. const Expr *peel(const Expr *E) const; /// Does this expression represent zero: '0'? @@ -141,14 +143,16 @@ class IvarInvalidationChecker : bool &InCalledAnotherInvalidationMethod, const MethToIvarMapTy &InPropertySetterToIvarMap, const MethToIvarMapTy &InPropertyGetterToIvarMap, - const PropToIvarMapTy &InPropertyToIvarMap) + const PropToIvarMapTy &InPropertyToIvarMap, + ASTContext &InCtx) : EnclosingMethod(InMeth), IVars(InIVars), CalledAnotherInvalidationMethod(InCalledAnotherInvalidationMethod), PropertySetterToIvarMap(InPropertySetterToIvarMap), PropertyGetterToIvarMap(InPropertyGetterToIvarMap), PropertyToIvarMap(InPropertyToIvarMap), - InvalidationMethod(0) {} + InvalidationMethod(0), + Ctx(InCtx) {} void VisitStmt(const Stmt *S) { VisitChildren(S); } @@ -363,7 +367,8 @@ void IvarInvalidationChecker::checkASTDecl(const ObjCMethodDecl *D, CalledAnotherInvalidationMethod, PropSetterToIvarMap, PropGetterToIvarMap, - PropertyToIvarMap).VisitStmt(D->getBody()); + PropertyToIvarMap, + BR.getContext()).VisitStmt(D->getBody()); if (CalledAnotherInvalidationMethod) return; @@ -467,21 +472,14 @@ void IvarInvalidationChecker::MethodCrawler::checkObjCPropertyRefExpr( bool IvarInvalidationChecker::MethodCrawler::isZero(const Expr *E) const { E = peel(E); - if (const IntegerLiteral *IL = dyn_cast(E)) - return IL->getValue() == 0; - - if (const CastExpr *ICE = dyn_cast(E)) - return ICE->getCastKind() == CK_NullToPointer; - return false; + return (E->isNullPointerConstant(Ctx, Expr::NPC_ValueDependentIsNotNull) + != Expr::NPCK_NotNull); } void IvarInvalidationChecker::MethodCrawler::check(const Expr *E) { E = peel(E); - if (const OpaqueValueExpr *OVE = dyn_cast(E)) - E = OVE->getSourceExpr(); - if (const ObjCIvarRefExpr *IvarRef = dyn_cast(E)) { checkObjCIvarRefExpr(IvarRef); return; @@ -500,7 +498,9 @@ void IvarInvalidationChecker::MethodCrawler::check(const Expr *E) { void IvarInvalidationChecker::MethodCrawler::VisitBinaryOperator( const BinaryOperator *BO) { - if (!BO->isAssignmentOp()) + VisitStmt(BO); + + if (BO->getOpcode() != BO_Assign) return; // Do we assign zero? @@ -509,8 +509,6 @@ void IvarInvalidationChecker::MethodCrawler::VisitBinaryOperator( // Check the variable we are assigning to. check(BO->getLHS()); - - VisitStmt(BO); } void IvarInvalidationChecker::MethodCrawler::VisitObjCMessageExpr( -- 2.7.4