[cfe-commits] r50083 - /cfe/trunk/lib/Analysis/GRExprEngine.cpp
Ted Kremenek
kremenek at apple.com
Mon Apr 21 21:56:29 PDT 2008
Author: kremenek
Date: Mon Apr 21 23:56:29 2008
New Revision: 50083
URL: http://llvm.org/viewvc/llvm-project?rev=50083&view=rev
Log:
Added null-dereference check for ArraySubscriptExpr.
Modified:
cfe/trunk/lib/Analysis/GRExprEngine.cpp
Modified: cfe/trunk/lib/Analysis/GRExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/GRExprEngine.cpp?rev=50083&r1=50082&r2=50083&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/GRExprEngine.cpp (original)
+++ cfe/trunk/lib/Analysis/GRExprEngine.cpp Mon Apr 21 23:56:29 2008
@@ -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;
More information about the cfe-commits
mailing list