aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/GRExprEngine.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2008-04-22 04:56:29 +0000
committerTed Kremenek <kremenek@apple.com>2008-04-22 04:56:29 +0000
commit540cbe2b60294fe7b926c26b4f1840f544fe3011 (patch)
tree2ec3f92089db2b3a3edff2606f7effaf447d7b8f /lib/Analysis/GRExprEngine.cpp
parent4cd3603978a3bfc0662fe31ac9ed546453d438ac (diff)
Added null-dereference check for ArraySubscriptExpr.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@50083 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/GRExprEngine.cpp')
-rw-r--r--lib/Analysis/GRExprEngine.cpp36
1 files changed, 35 insertions, 1 deletions
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<ArraySubscriptExpr>(S), Pred, Dst, false);
+ break;
case Stmt::AsmStmtClass:
VisitAsmStmt(cast<AsmStmt>(S), Pred, Dst);
@@ -296,7 +300,7 @@ void GRExprEngine::Visit(Stmt* S, NodeTy* Pred, NodeSet& Dst) {
}
case Stmt::ParenExprClass:
- Visit(cast<ParenExpr>(S)->getSubExpr(), Pred, Dst);
+ Visit(cast<ParenExpr>(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<ArraySubscriptExpr>(Ex), Pred, Dst, true);
+ return;
+
case Stmt::DeclRefExprClass:
Dst.Add(Pred);
return;