[analyzer] Add getLocationContext to CheckerContext

CheckerContext::getPredecessor is only used to get to the LocationContext
half of the times.

llvm-svn: 143061
This commit is contained in:
Anna Zaks 2011-10-26 21:06:44 +00:00
parent 6b1c21268d
commit c9abbe2b3e
9 changed files with 25 additions and 24 deletions

View File

@ -50,7 +50,7 @@ public:
return Eng.getStoreManager();
}
ExplodedNode *&getPredecessor() { return Pred; }
ExplodedNode *getPredecessor() { return Pred; }
const ProgramState *getState() { return Pred->getState(); }
/// \brief Returns the number of times the current block has been visited
@ -63,6 +63,10 @@ public:
return Eng.getContext();
}
const LocationContext *getLocationContext() {
return Pred->getLocationContext();
}
BugReporter &getBugReporter() {
return Eng.getBugReporter();
}
@ -139,14 +143,14 @@ public:
}
private:
ExplodedNode *addTransitionImpl(const ProgramState *state,
bool markAsSink,
ExplodedNode *pred = 0,
const ProgramPointTag *tag = 0) {
assert(state);
ExplodedNode *node = NB.generateNode(tag ? Location.withTag(tag) : Location,
state,
pred ? pred : Pred, markAsSink);
ExplodedNode *addTransitionImpl(const ProgramState *State,
bool MarkAsSink,
ExplodedNode *P = 0,
const ProgramPointTag *Tag = 0) {
assert(State);
ExplodedNode *node = NB.generateNode(Tag ? Location.withTag(Tag) : Location,
State,
P ? P : Pred, MarkAsSink);
return node;
}
};

View File

@ -57,8 +57,7 @@ bool BuiltinFunctionChecker::evalCall(const CallExpr *CE,
// FIXME: Refactor into StoreManager itself?
MemRegionManager& RM = C.getStoreManager().getRegionManager();
const AllocaRegion* R =
RM.getAllocaRegion(CE, C.getCurrentBlockCount(),
C.getPredecessor()->getLocationContext());
RM.getAllocaRegion(CE, C.getCurrentBlockCount(), C.getLocationContext());
// Set the extent of the region in bytes. This enables us to use the
// SVal of the argument directly. If we save the extent in bits, we

View File

@ -1733,7 +1733,7 @@ void CStringChecker::checkPreStmt(const DeclStmt *DS, CheckerContext &C) const {
if (!isa<StringLiteral>(Init))
continue;
Loc VarLoc = state->getLValue(D, C.getPredecessor()->getLocationContext());
Loc VarLoc = state->getLValue(D, C.getLocationContext());
const MemRegion *MR = VarLoc.getAsRegion();
if (!MR)
continue;

View File

@ -395,8 +395,7 @@ const MemRegion *IteratorsChecker::getRegion(const ProgramState *state,
// with the same tag.
void IteratorsChecker::checkExpr(CheckerContext &C, const Expr *E) const {
const ProgramState *state = C.getState();
const MemRegion *MR = getRegion(state, E,
C.getPredecessor()->getLocationContext());
const MemRegion *MR = getRegion(state, E, C.getLocationContext());
if (!MR)
return;
@ -466,7 +465,7 @@ void IteratorsChecker::checkPreStmt(const CallExpr *CE,
void IteratorsChecker::checkPreStmt(const CXXOperatorCallExpr *OCE,
CheckerContext &C) const
{
const LocationContext *LC = C.getPredecessor()->getLocationContext();
const LocationContext *LC = C.getLocationContext();
const ProgramState *state = C.getState();
OverloadedOperatorKind Kind = OCE->getOperator();
if (Kind == OO_Equal) {
@ -525,7 +524,7 @@ void IteratorsChecker::checkPreStmt(const DeclStmt *DS,
// Get the MemRegion associated with the iterator and mark it as Undefined.
const ProgramState *state = C.getState();
Loc VarLoc = state->getLValue(VD, C.getPredecessor()->getLocationContext());
Loc VarLoc = state->getLValue(VD, C.getLocationContext());
const MemRegion *MR = VarLoc.getAsRegion();
if (!MR)
return;
@ -545,8 +544,7 @@ void IteratorsChecker::checkPreStmt(const DeclStmt *DS,
E = M->GetTemporaryExpr();
if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E))
InitEx = ICE->getSubExpr();
state = handleAssign(state, MR, InitEx,
C.getPredecessor()->getLocationContext());
state = handleAssign(state, MR, InitEx, C.getLocationContext());
}
}
}

View File

@ -198,7 +198,7 @@ static void setFlag(const ProgramState *state, SVal val, CheckerContext &C) {
static QualType parameterTypeFromSVal(SVal val, CheckerContext &C) {
const StackFrameContext *
SFC = C.getPredecessor()->getLocationContext()->getCurrentStackFrame();
SFC = C.getLocationContext()->getCurrentStackFrame();
if (const loc::MemRegionVal* X = dyn_cast<loc::MemRegionVal>(&val)) {
const MemRegion* R = X->getRegion();
if (const VarRegion *VR = R->getAs<VarRegion>())

View File

@ -2501,7 +2501,7 @@ void RetainCountChecker::checkPostStmt(const BlockExpr *BE,
// via captured variables, even though captured variables result in a copy
// and in implicit increment/decrement of a retain count.
SmallVector<const MemRegion*, 10> Regions;
const LocationContext *LC = C.getPredecessor()->getLocationContext();
const LocationContext *LC = C.getLocationContext();
MemRegionManager &MemMgr = C.getSValBuilder().getRegionManager();
for ( ; I != E; ++I) {
@ -2681,7 +2681,7 @@ void RetainCountChecker::checkSummary(const RetainSummary &Summ,
// Evaluate the effect on the message receiver.
bool ReceiverIsTracked = false;
if (!hasErr && CallOrMsg.isObjCMessage()) {
const LocationContext *LC = C.getPredecessor()->getLocationContext();
const LocationContext *LC = C.getLocationContext();
SVal Receiver = CallOrMsg.getInstanceMessageReceiver(LC);
if (SymbolRef Sym = Receiver.getAsLocSymbol()) {
if (const RefVal *T = state->get<RefBindings>(Sym)) {

View File

@ -150,7 +150,7 @@ void StackAddrEscapeChecker::checkEndPath(CheckerContext &Ctx) const {
CallBack(CheckerContext &CC) :
Ctx(CC),
CurSFC(CC.getPredecessor()->getLocationContext()->getCurrentStackFrame())
CurSFC(CC.getLocationContext()->getCurrentStackFrame())
{}
bool HandleBinding(StoreManager &SMgr, Store store,

View File

@ -72,7 +72,7 @@ UndefCapturedBlockVarChecker::checkPostStmt(const BlockExpr *BE,
continue;
// Get the VarRegion associated with VD in the local stack frame.
const LocationContext *LC = C.getPredecessor()->getLocationContext();
const LocationContext *LC = C.getLocationContext();
VR = C.getSValBuilder().getRegionManager().getVarRegion(VD, LC);
SVal VRVal = state->getSVal(VR);

View File

@ -117,7 +117,7 @@ void VLASizeChecker::checkPreStmt(const DeclStmt *DS, CheckerContext &C) const {
cast<NonLoc>(EleSizeVal), SizeTy);
// Finally, assume that the array's extent matches the given size.
const LocationContext *LC = C.getPredecessor()->getLocationContext();
const LocationContext *LC = C.getLocationContext();
DefinedOrUnknownSVal Extent =
state->getRegion(VD, LC)->getExtent(svalBuilder);
DefinedOrUnknownSVal ArraySize = cast<DefinedOrUnknownSVal>(ArraySizeVal);