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 86d2cc9..677ef1c 100644
--- a/lib/Analysis/GRExprEngine.cpp
+++ b/lib/Analysis/GRExprEngine.cpp
@@ -218,6 +218,10 @@
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 @@
}
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 @@
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 @@
default:
break;
+ case Stmt::ArraySubscriptExprClass:
+ VisitArraySubscriptExpr(cast<ArraySubscriptExpr>(Ex), Pred, Dst, true);
+ return;
+
case Stmt::DeclRefExprClass:
Dst.Add(Pred);
return;