Reduce nesting by using early exits. No functionality change.

llvm-svn: 91610
This commit is contained in:
Ted Kremenek 2009-12-17 19:17:27 +00:00
parent 2d1ffe028f
commit da7d55a4a8
1 changed files with 46 additions and 35 deletions

View File

@ -334,32 +334,42 @@ const GRState* GRExprEngine::getInitialState(const LocationContext *InitLoc) {
// FIXME: It would be nice if we had a more general mechanism to add
// such preconditions. Some day.
do {
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 (const IdentifierInfo *II = FD->getIdentifier()) {
if (II->getName() == "main" && FD->getNumParams() > 0) {
const IdentifierInfo *II = FD->getIdentifier();
if (!II || !(II->getName() == "main" && FD->getNumParams() > 0))
break;
const ParmVarDecl *PD = FD->getParamDecl(0);
QualType T = PD->getType();
if (T->isIntegerType())
if (const MemRegion *R = state->getRegion(PD, InitLoc)) {
if (!T->isIntegerType())
break;
const MemRegion *R = state->getRegion(PD, InitLoc);
if (!R)
break;
SVal V = state->getSVal(loc::MemRegionVal(R));
SVal Constraint_untested = EvalBinOp(state, BinaryOperator::GT, V,
ValMgr.makeZeroVal(T),
getContext().IntTy);
if (DefinedOrUnknownSVal *Constraint =
dyn_cast<DefinedOrUnknownSVal>(&Constraint_untested)) {
DefinedOrUnknownSVal *Constraint =
dyn_cast<DefinedOrUnknownSVal>(&Constraint_untested);
if (!Constraint)
break;
if (const GRState *newState = state->Assume(*Constraint, true))
state = newState;
break;
}
}
}
}
}
else if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) {
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();
@ -372,6 +382,7 @@ const GRState* GRExprEngine::getInitialState(const LocationContext *InitLoc) {
assert(state && "'self' cannot be null");
}
}
} while (0);
return state;
}