aboutsummaryrefslogtreecommitdiff
path: root/lib/StaticAnalyzer/Core/ExprEngineObjC.cpp
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2012-09-22 01:24:38 +0000
committerJordan Rose <jordan_rose@apple.com>2012-09-22 01:24:38 +0000
commit991bcb4370fe849603346ebbddc8dd47bc29d235 (patch)
tree13ae959d39be697057da8cdedf857e2680e7dd64 /lib/StaticAnalyzer/Core/ExprEngineObjC.cpp
parentdd1d7d88f1fe6d7d7e79acaec3f83bc10d9f7b97 (diff)
[analyzer] Check that an ObjCIvarRefExpr's base is non-null even as an lvalue.
Like with struct fields, we want to catch cases like this early, so that we can produce better diagnostics and path notes: PointObj *p = nil; int *px = &p->_x; // should warn here *px = 1; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@164442 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/StaticAnalyzer/Core/ExprEngineObjC.cpp')
-rw-r--r--lib/StaticAnalyzer/Core/ExprEngineObjC.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/StaticAnalyzer/Core/ExprEngineObjC.cpp b/lib/StaticAnalyzer/Core/ExprEngineObjC.cpp
index 51dda19b53..ee315a4604 100644
--- a/lib/StaticAnalyzer/Core/ExprEngineObjC.cpp
+++ b/lib/StaticAnalyzer/Core/ExprEngineObjC.cpp
@@ -25,11 +25,21 @@ void ExprEngine::VisitLvalObjCIvarRefExpr(const ObjCIvarRefExpr *Ex,
ProgramStateRef state = Pred->getState();
const LocationContext *LCtx = Pred->getLocationContext();
SVal baseVal = state->getSVal(Ex->getBase(), LCtx);
+
+ // First check that the base object is valid.
+ ExplodedNodeSet DstLoc;
+ evalLocation(DstLoc, Ex, Ex, Pred, state, baseVal,
+ /*Tag=*/0, /*isLoad=*/true);
+
+ // Bind the lvalue to the expression.
SVal location = state->getLValue(Ex->getDecl(), baseVal);
ExplodedNodeSet dstIvar;
- StmtNodeBuilder Bldr(Pred, dstIvar, *currBldrCtx);
- Bldr.generateNode(Ex, Pred, state->BindExpr(Ex, LCtx, location));
+ StmtNodeBuilder Bldr(DstLoc, dstIvar, *currBldrCtx);
+ for (ExplodedNodeSet::iterator I = DstLoc.begin(), E = DstLoc.end();
+ I != E; ++I) {
+ Bldr.generateNode(Ex, (*I), (*I)->getState()->BindExpr(Ex, LCtx, location));
+ }
// Perform the post-condition check of the ObjCIvarRefExpr and store
// the created nodes in 'Dst'.