From: Ted Kremenek Date: Tue, 22 Apr 2008 04:56:29 +0000 (+0000) Subject: Added null-dereference check for ArraySubscriptExpr. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=540cbe2b60294fe7b926c26b4f1840f544fe3011;p=clang Added null-dereference check for ArraySubscriptExpr. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@50083 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/GRExprEngine.cpp b/lib/Analysis/GRExprEngine.cpp index 86d2cc9ae5..677ef1cdc9 100644 --- a/lib/Analysis/GRExprEngine.cpp +++ b/lib/Analysis/GRExprEngine.cpp @@ -218,6 +218,10 @@ void GRExprEngine::Visit(Stmt* S, NodeTy* Pred, NodeSet& Dst) { Dst.Add(Pred); // No-op. Simply propagate the current state unchanged. break; + + case Stmt::ArraySubscriptExprClass: + VisitArraySubscriptExpr(cast(S), Pred, Dst, false); + break; case Stmt::AsmStmtClass: VisitAsmStmt(cast(S), Pred, Dst); @@ -296,7 +300,7 @@ void GRExprEngine::Visit(Stmt* S, NodeTy* Pred, NodeSet& Dst) { } case Stmt::ParenExprClass: - Visit(cast(S)->getSubExpr(), Pred, Dst); + Visit(cast(S)->getSubExpr()->IgnoreParens(), Pred, Dst); break; case Stmt::SizeOfAlignOfTypeExprClass: @@ -714,6 +718,32 @@ void GRExprEngine::VisitDeclRefExpr(DeclRefExpr* D, NodeTy* Pred, NodeSet& Dst){ MakeNode(Dst, D, Pred, SetBlkExprRVal(St, D, Y)); } +/// VisitArraySubscriptExpr - Transfer function for array accesses +void GRExprEngine::VisitArraySubscriptExpr(ArraySubscriptExpr* A, NodeTy* Pred, + NodeSet& Dst, bool asLVal) { + + Expr* Base = A->getBase()->IgnoreParens(); + + // Evaluate the base. + NodeSet Tmp1; + Visit(Base, Pred, Tmp1); + + // Dereference the base. + NodeSet Tmp2; + + for (NodeSet::iterator I=Tmp1.begin(), E=Tmp1.end(); I!=E; ++I) { + ValueState* St = GetState(*I); + VisitDeref(Base, GetRVal(St, Base), St, *I, Tmp2, true); + } + + // Get the index. + Tmp1.clear(); + Expr* Index = A->getIdx()->IgnoreParens(); + + for (NodeSet::iterator I=Tmp2.begin(), E=Tmp2.end(); I!=E; ++I) + Visit(Index, *I, Dst); +} + /// VisitMemberExpr - Transfer function for member expressions. void GRExprEngine::VisitMemberExpr(MemberExpr* M, NodeTy* Pred, NodeSet& Dst, bool asLVal) { @@ -1431,6 +1461,10 @@ void GRExprEngine::VisitLVal(Expr* Ex, NodeTy* Pred, NodeSet& Dst) { default: break; + case Stmt::ArraySubscriptExprClass: + VisitArraySubscriptExpr(cast(Ex), Pred, Dst, true); + return; + case Stmt::DeclRefExprClass: Dst.Add(Pred); return;