diff options
| author | Ted Kremenek <kremenek@apple.com> | 2009-09-09 20:36:12 +0000 |
|---|---|---|
| committer | Ted Kremenek <kremenek@apple.com> | 2009-09-09 20:36:12 +0000 |
| commit | 84c6f0a1e6a951276fde603431b7917d43cee089 (patch) | |
| tree | 7e4fa2c03a098ed3dc03c1d3ee0fe56fe3227bc1 /clang/lib/Analysis/GRExprEngine.cpp | |
| parent | 716a8c92d0a9b241aa84fd8884892c6565810436 (diff) | |
| download | bcm5719-llvm-84c6f0a1e6a951276fde603431b7917d43cee089.tar.gz bcm5719-llvm-84c6f0a1e6a951276fde603431b7917d43cee089.zip | |
Implement: <rdar://problem/7185647> [RegionStore] 'self' cannot be NULL upon entry to a method
Here we implement this as a precondition within GRExprEngine, even though it is
related to how BasicStoreManager and RegionStoreManager model 'self'
differently. Putting this as a high-level precondition is more general, which is
why it isn't in RegionStore.cpp.
llvm-svn: 81378
Diffstat (limited to 'clang/lib/Analysis/GRExprEngine.cpp')
| -rw-r--r-- | clang/lib/Analysis/GRExprEngine.cpp | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/clang/lib/Analysis/GRExprEngine.cpp b/clang/lib/Analysis/GRExprEngine.cpp index b4b69cdcd61..ff9554c836a 100644 --- a/clang/lib/Analysis/GRExprEngine.cpp +++ b/clang/lib/Analysis/GRExprEngine.cpp @@ -198,11 +198,15 @@ void GRExprEngine::AddCheck(GRSimpleAPICheck *A) { const GRState* GRExprEngine::getInitialState(const LocationContext *InitLoc) { const GRState *state = StateMgr.getInitialState(InitLoc); - // Precondition: the first argument of 'main' is an integer guaranteed - // to be > 0. + // Preconditions. + // FIXME: It would be nice if we had a more general mechanism to add // such preconditions. Some day. - if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(InitLoc->getDecl())) + const Decl *D = InitLoc->getDecl(); + + if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { + // Precondition: the first argument of 'main' is an integer guaranteed + // to be > 0. if (strcmp(FD->getIdentifier()->getName(), "main") == 0 && FD->getNumParams() > 0) { const ParmVarDecl *PD = FD->getParamDecl(0); @@ -218,7 +222,21 @@ const GRState* GRExprEngine::getInitialState(const LocationContext *InitLoc) { state = newState; } } - + } + else if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) { + // Precondition: 'self' is always non-null upon entry to an Objective-C + // method. + const ImplicitParamDecl *SelfD = MD->getSelfDecl(); + const MemRegion *R = state->getRegion(SelfD, InitLoc); + SVal V = state->getSVal(loc::MemRegionVal(R)); + + if (const Loc *LV = dyn_cast<Loc>(&V)) { + // Assume that the pointer value in 'self' is non-null. + state = state->assume(*LV, true); + assert(state && "'self' cannot be null"); + } + } + return state; } |

