RVal GetRVal(const GRState* St, LVal LV, QualType T = QualType()) {
return StateMgr.GetRVal(St, LV, T);
}
+
+ // Get the lvalue of an expression.
+ RVal GetLValue(const GRState* St, const Expr* Ex) {
+ return StateMgr.GetLValue(St, Ex);
+ }
inline NonLVal MakeConstantVal(uint64_t X, Expr* Ex) {
return NonLVal::MakeVal(getBasicVals(), X, Ex->getType());
/// other functions that handle specific kinds of statements.
void Visit(Stmt* S, NodeTy* Pred, NodeSet& Dst);
- /// VisitLVal - Similar to Visit, but the specified expression is assummed
- /// to be evaluated under the context where it evaluates to an LVal. For
- /// example, if Ex is a DeclRefExpr, under Visit Ex would evaluate to the
- /// value bound to Ex in the symbolic state, while under VisitLVal it would
- /// evaluate to an LVal representing the location of the referred Decl.
- void VisitLVal(Expr* Ex, NodeTy* Pred, NodeSet& Dst);
+ /// VisitLValue - Evaluate the lvalue of the expression. For example, if Ex is
+ /// a DeclRefExpr, it evaluates to the MemRegionVal which represents its
+ /// storage location. Note that not all kinds of expressions has lvalue.
+ void VisitLValue(Expr* Ex, NodeTy* Pred, NodeSet& Dst);
/// VisitArraySubscriptExpr - Transfer function for array accesses.
void VisitArraySubscriptExpr(ArraySubscriptExpr* Ex, NodeTy* Pred,
- NodeSet& Dst, bool asLVal);
+ NodeSet& Dst, bool asLValue);
/// VisitAsmStmt - Transfer function logic for inline asm.
void VisitAsmStmt(AsmStmt* A, NodeTy* Pred, NodeSet& Dst);
NodeSet& Dst);
/// VisitCast - Transfer function logic for all casts (implicit and explicit).
- void VisitCast(Expr* CastE, Expr* Ex, NodeTy* Pred, NodeSet& Dst);
+ void VisitCast(Expr* CastE, Expr* Ex, NodeTy* Pred, NodeSet& Dst);
/// VisitDeclRefExpr - Transfer function logic for DeclRefExprs.
void VisitDeclRefExpr(DeclRefExpr* DR, NodeTy* Pred, NodeSet& Dst,
- bool asLval);
+ bool asLValue);
/// VisitDeclStmt - Transfer function logic for DeclStmts.
void VisitDeclStmt(DeclStmt* DS, NodeTy* Pred, NodeSet& Dst);
void VisitLogicalExpr(BinaryOperator* B, NodeTy* Pred, NodeSet& Dst);
/// VisitMemberExpr - Transfer function for member expressions.
- void VisitMemberExpr(MemberExpr* M, NodeTy* Pred, NodeSet& Dst, bool asLVal);
+ void VisitMemberExpr(MemberExpr* M, NodeTy* Pred, NodeSet& Dst,bool asLValue);
/// VisitObjCMessageExpr - Transfer function for ObjC message expressions.
void VisitObjCMessageExpr(ObjCMessageExpr* ME, NodeTy* Pred, NodeSet& Dst);
/// VisitUnaryOperator - Transfer function logic for unary operators.
void VisitUnaryOperator(UnaryOperator* B, NodeTy* Pred, NodeSet& Dst,
- bool asLVal);
+ bool asLValue);
bool CheckDivideZero(Expr* Ex, const GRState* St, NodeTy* Pred,
RVal Denom);
private:
EnvironmentManager EnvMgr;
- llvm::OwningPtr<StoreManager> StMgr;
+ llvm::OwningPtr<StoreManager> StoreMgr;
llvm::OwningPtr<ConstraintManager> ConstraintMgr;
GRState::IntSetTy::Factory ISetFactory;
Alloc(alloc),
cfg(c),
Liveness(L) {
- StMgr.reset((*CreateStoreManager)(*this));
+ StoreMgr.reset((*CreateStoreManager)(*this));
ConstraintMgr.reset((*CreateConstraintManager)(*this));
}
SymbolManager& getSymbolManager() { return SymMgr; }
LiveVariables& getLiveVariables() { return Liveness; }
llvm::BumpPtrAllocator& getAllocator() { return Alloc; }
- MemRegionManager& getRegionManager() { return StMgr->getRegionManager(); }
+ MemRegionManager& getRegionManager() { return StoreMgr->getRegionManager(); }
typedef StoreManager::DeadSymbolsTy DeadSymbolsTy;
}
LVal getLVal(const VarDecl* D) {
- return StMgr->getLVal(D);
+ return StoreMgr->getLVal(D);
}
-
+
+ // Get the lvalue of expression.
+ RVal GetLValue(const GRState* St, const Expr* Ex) {
+ // Forward to store manager. The lvalue of an expression is determined by
+ // the store manager.
+ return StoreMgr->getLValue(St, Ex);
+ }
+
// Methods that query & manipulate the Environment.
RVal GetRVal(const GRState* St, Expr* Ex) {
return St->getEnvironment().GetRVal(Ex, BasicVals);
}
+
+ RVal GetRVal(const GRState* St, const Expr* Ex) {
+ return St->getEnvironment().GetRVal(Ex, BasicVals);
+ }
RVal GetBlkExprRVal(const GRState* St, Expr* Ex) {
return St->getEnvironment().GetBlkExprRVal(Ex, BasicVals);
// Methods that query & manipulate the Store.
void iterBindings(const GRState* state, StoreManager::BindingsHandler& F) {
- StMgr->iterBindings(state->getStore(), F);
+ StoreMgr->iterBindings(state->getStore(), F);
}
RVal GetRVal(const GRState* St, LVal LV, QualType T = QualType()) {
- return StMgr->GetRVal(St->getStore(), LV, T);
+ return StoreMgr->GetRVal(St->getStore(), LV, T);
}
void SetRVal(GRState& St, LVal LV, RVal V) {
- St.St = StMgr->SetRVal(St.St, LV, V);
+ St.St = StoreMgr->SetRVal(St.St, LV, V);
}
const GRState* SetRVal(const GRState* St, LVal LV, RVal V);
void Unbind(GRState& St, LVal LV) {
- St.St = StMgr->Remove(St.St, LV);
+ St.St = StoreMgr->Remove(St.St, LV);
}
const GRState* Unbind(const GRState* St, LVal LV);
}
}
-void GRExprEngine::VisitLVal(Expr* Ex, NodeTy* Pred, NodeSet& Dst) {
+void GRExprEngine::VisitLValue(Expr* Ex, NodeTy* Pred, NodeSet& Dst) {
Ex = Ex->IgnoreParens();
switch (Ex->getStmtClass()) {
default:
- Visit(Ex, Pred, Dst);
- return;
+ Ex->dump();
+ assert(0 && "Other kinds of expressions do not have lvalue.");
case Stmt::ArraySubscriptExprClass:
VisitArraySubscriptExpr(cast<ArraySubscriptExpr>(Ex), Pred, Dst, true);
// Transfer functions: Loads and stores.
//===----------------------------------------------------------------------===//
-void GRExprEngine::VisitDeclRefExpr(DeclRefExpr* D, NodeTy* Pred, NodeSet& Dst,
- bool asLVal) {
+void GRExprEngine::VisitDeclRefExpr(DeclRefExpr* Ex, NodeTy* Pred, NodeSet& Dst,
+ bool asLValue) {
const GRState* St = GetState(Pred);
- RVal X = RVal::MakeVal(getStateManager(), D);
-
- if (asLVal)
- MakeNode(Dst, D, Pred, SetRVal(St, D, cast<LVal>(X)));
- else {
- RVal V = isa<lval::MemRegionVal>(X) ? GetRVal(St, cast<LVal>(X)) : X;
- MakeNode(Dst, D, Pred, SetRVal(St, D, V));
+
+ const ValueDecl* D = Ex->getDecl();
+
+ if (const VarDecl* VD = dyn_cast<VarDecl>(D)) {
+
+ QualType T = VD->getType();
+ if (T->isArrayType()) {
+ assert(!asLValue && "Array variable has no lvalue.");
+
+ // C++ standard says array value should be implicitly converted to pointer
+ // in some cases. We don't have such context information right now. We
+ // use a MemRegionVal to represent this. May be changed in the future.
+
+ RVal V = lval::MemRegionVal(StateMgr.getRegion(VD));
+ MakeNode(Dst, Ex, Pred, SetRVal(St, Ex, V));
+ return;
+ }
+
+ RVal V = GetLValue(St, Ex);
+ if (asLValue)
+ MakeNode(Dst, Ex, Pred, SetRVal(St, Ex, V));
+ else
+ EvalLoad(Dst, Ex, Pred, St, V);
+ return;
+
+ } else if (const EnumConstantDecl* ED = dyn_cast<EnumConstantDecl>(D)) {
+ assert(!asLValue && "EnumConstantDecl does not have lvalue.");
+
+ BasicValueFactory& BasicVals = StateMgr.getBasicVals();
+ RVal V = nonlval::ConcreteInt(BasicVals.getValue(ED->getInitVal()));
+ MakeNode(Dst, Ex, Pred, SetRVal(St, Ex, V));
+ return;
+
+ } else if (const FunctionDecl* FD = dyn_cast<FunctionDecl>(D)) {
+ assert(!asLValue && "FunctionDecl does not have lvalue.");
+
+ RVal V = lval::FuncVal(FD);
+ MakeNode(Dst, Ex, Pred, SetRVal(St, Ex, V));
+ return;
}
+
+ assert (false &&
+ "ValueDecl support for this ValueDecl not implemented.");
}
/// VisitArraySubscriptExpr - Transfer function for array accesses
void GRExprEngine::VisitArraySubscriptExpr(ArraySubscriptExpr* A, NodeTy* Pred,
- NodeSet& Dst, bool asLVal) {
+ NodeSet& Dst, bool asLValue) {
Expr* Base = A->getBase()->IgnoreParens();
Expr* Idx = A->getIdx()->IgnoreParens();
- // Always visit the base as an LVal expression. This computes the
- // abstract address of the base object.
NodeSet Tmp;
-
- if (LVal::IsLValType(Base->getType())) // Base always is an LVal.
- Visit(Base, Pred, Tmp);
- else
- VisitLVal(Base, Pred, Tmp);
+
+ // Get Base's rvalue, which should be an LocVal.
+ Visit(Base, Pred, Tmp);
for (NodeSet::iterator I1=Tmp.begin(), E1=Tmp.end(); I1!=E1; ++I1) {
// Evaluate the index.
-
NodeSet Tmp2;
Visit(Idx, *I1, Tmp2);
for (NodeSet::iterator I2=Tmp2.begin(), E2=Tmp2.end(); I2!=E2; ++I2) {
const GRState* St = GetState(*I2);
- RVal BaseV = GetRVal(St, Base);
- RVal IdxV = GetRVal(St, Idx);
-
- // If IdxV is 0, return just BaseV.
-
- bool useBase = false;
-
- if (nonlval::ConcreteInt* IdxInt = dyn_cast<nonlval::ConcreteInt>(&IdxV))
- useBase = IdxInt->getValue() == 0;
-
- RVal V = useBase ? BaseV : lval::ArrayOffset::Make(getBasicVals(), BaseV,IdxV);
+ RVal V = GetLValue(St, A);
- if (asLVal)
+ if (asLValue)
MakeNode(Dst, A, *I2, SetRVal(St, A, V));
else
EvalLoad(Dst, A, *I2, St, V);
/// VisitMemberExpr - Transfer function for member expressions.
void GRExprEngine::VisitMemberExpr(MemberExpr* M, NodeTy* Pred,
- NodeSet& Dst, bool asLVal) {
+ NodeSet& Dst, bool asLValue) {
Expr* Base = M->getBase()->IgnoreParens();
- // Always visit the base as an LVal expression. This computes the
- // abstract address of the base object.
NodeSet Tmp;
-
- if (asLVal) {
-
- if (LVal::IsLValType(Base->getType())) // Base always is an LVal.
- Visit(Base, Pred, Tmp);
- else
- VisitLVal(Base, Pred, Tmp);
-
- for (NodeSet::iterator I=Tmp.begin(), E=Tmp.end(); I!=E; ++I) {
- const GRState* St = GetState(*I);
- RVal BaseV = GetRVal(St, Base);
-
- RVal V = lval::FieldOffset::Make(getBasicVals(), GetRVal(St, Base),
- M->getMemberDecl());
-
- MakeNode(Dst, M, *I, SetRVal(St, M, V));
- }
-
- return;
- }
- // Evaluate the base. Can be an LVal or NonLVal (depends on whether
- // or not isArrow() is true).
+ // Get Base expr's rvalue.
Visit(Base, Pred, Tmp);
-
- for (NodeSet::iterator I=Tmp.begin(), E=Tmp.end(); I!=E; ++I) {
+ for (NodeSet::iterator I = Tmp.begin(), E = Tmp.end(); I != E; ++I) {
const GRState* St = GetState(*I);
- RVal BaseV = GetRVal(St, Base);
-
- if (LVal::IsLValType(Base->getType())) {
-
- assert (M->isArrow());
-
- RVal V = lval::FieldOffset::Make(getBasicVals(), GetRVal(St, Base),
- M->getMemberDecl());
-
- EvalLoad(Dst, M, *I, St, V);
- }
- else {
-
- assert (!M->isArrow());
-
- if (BaseV.isUnknownOrUndef()) {
- MakeNode(Dst, M, *I, SetRVal(St, M, BaseV));
- continue;
- }
-
- // FIXME: Implement nonlval objects representing struct temporaries.
- assert (isa<NonLVal>(BaseV));
- MakeNode(Dst, M, *I, SetRVal(St, M, UnknownVal()));
- }
+ RVal L = GetLValue(St, M);
+ if (asLValue)
+ MakeNode(Dst, M, *I, SetRVal(St, M, L));
+ else
+ EvalLoad(Dst, M, *I, St, L);
}
}
NodeSet DstTmp;
Expr* Callee = CE->getCallee()->IgnoreParens();
- VisitLVal(Callee, Pred, DstTmp);
+ Visit(Callee, Pred, DstTmp);
// Finally, evaluate the function call.
for (NodeSet::iterator DI = DstTmp.begin(), DE = DstTmp.end(); DI!=DE; ++DI) {
//===----------------------------------------------------------------------===//
void GRExprEngine::VisitCast(Expr* CastE, Expr* Ex, NodeTy* Pred, NodeSet& Dst){
-
NodeSet S1;
QualType T = CastE->getType();
if (T->isReferenceType())
- VisitLVal(Ex, Pred, S1);
+ VisitLValue(Ex, Pred, S1);
else
Visit(Ex, Pred, S1);
void GRExprEngine::VisitUnaryOperator(UnaryOperator* U, NodeTy* Pred,
- NodeSet& Dst, bool asLVal) {
+ NodeSet& Dst, bool asLValue) {
switch (U->getOpcode()) {
const GRState* St = GetState(*I);
RVal location = GetRVal(St, Ex);
- if (asLVal)
+ if (asLValue)
MakeNode(Dst, U, *I, SetRVal(St, U, location));
else
EvalLoad(Dst, U, *I, St, location);
Dst.Add(Pred);
return;
- case UnaryOperator::Plus: assert (!asLVal); // FALL-THROUGH.
+ case UnaryOperator::Plus: assert (!asLValue); // FALL-THROUGH.
case UnaryOperator::Extension: {
// Unary "+" is a no-op, similar to a parentheses. We still have places
case UnaryOperator::AddrOf: {
- assert (!asLVal);
+ assert(!asLValue);
Expr* Ex = U->getSubExpr()->IgnoreParens();
NodeSet Tmp;
- VisitLVal(Ex, Pred, Tmp);
+ VisitLValue(Ex, Pred, Tmp);
for (NodeSet::iterator I=Tmp.begin(), E=Tmp.end(); I!=E; ++I) {
const GRState* St = GetState(*I);
case UnaryOperator::Minus:
case UnaryOperator::Not: {
- assert (!asLVal);
+ assert (!asLValue);
Expr* Ex = U->getSubExpr()->IgnoreParens();
NodeSet Tmp;
Visit(Ex, Pred, Tmp);
assert (U->isIncrementDecrementOp());
NodeSet Tmp;
Expr* Ex = U->getSubExpr()->IgnoreParens();
- VisitLVal(Ex, Pred, Tmp);
+ VisitLValue(Ex, Pred, Tmp);
for (NodeSet::iterator I = Tmp.begin(), E = Tmp.end(); I!=E; ++I) {
}
NodeSet Tmp;
- VisitLVal(*I, Pred, Tmp);
+ VisitLValue(*I, Pred, Tmp);
++I;
Expr* RHS = B->getRHS()->IgnoreParens();
if (B->isAssignmentOp())
- VisitLVal(LHS, Pred, Tmp1);
+ VisitLValue(LHS, Pred, Tmp1);
else
Visit(LHS, Pred, Tmp1);
// Simulate the effects of a "store": bind the value of the RHS
// to the L-Value represented by the LHS.
- EvalStore(Dst, B, LHS, *I2, SetRVal(St, B, RightV), LeftV, RightV);
+ EvalStore(Dst, B, LHS, *I2, SetRVal(St, B, RightV), LeftV, RightV);
continue;
}
// Clean up the store.
DSymbols.clear();
- NewSt.St = StMgr->RemoveDeadBindings(St->getStore(), Loc, Liveness,
+ NewSt.St = StoreMgr->RemoveDeadBindings(St->getStore(), Loc, Liveness,
RegionRoots, LSymbols, DSymbols);
return ConstraintMgr->RemoveDeadBindings(getPersistentState(NewSt),
RVal V) {
Store OldStore = St->getStore();
- Store NewStore = StMgr->SetRVal(OldStore, LV, V);
+ Store NewStore = StoreMgr->SetRVal(OldStore, LV, V);
if (NewStore == OldStore)
return St;
Store NewStore;
if (Ex)
- NewStore = StMgr->AddDecl(OldStore, VD, Ex,
+ NewStore = StoreMgr->AddDecl(OldStore, VD, Ex,
GetRVal(St, Ex), Count);
else
- NewStore = StMgr->AddDecl(OldStore, VD, Ex);
+ NewStore = StoreMgr->AddDecl(OldStore, VD, Ex);
if (NewStore == OldStore)
return St;
const GRState* GRStateManager::Unbind(const GRState* St, LVal LV) {
Store OldStore = St->getStore();
- Store NewStore = StMgr->Remove(OldStore, LV);
+ Store NewStore = StoreMgr->Remove(OldStore, LV);
if (NewStore == OldStore)
return St;
const GRState* GRStateManager::getInitialState() {
GRState StateImpl(EnvMgr.getInitialEnvironment(),
- StMgr->getInitialStore(),
+ StoreMgr->getInitialStore(),
GDMFactory.GetEmptyMap());
return getPersistentState(StateImpl);
void GRStateRef::print(std::ostream& Out, const char* nl, const char* sep)const{
GRState::Printer **beg = Mgr->Printers.empty() ? 0 : &Mgr->Printers[0];
GRState::Printer **end = !beg ? 0 : beg + Mgr->Printers.size();
- St->print(Out, *Mgr->StMgr, *Mgr->ConstraintMgr, beg, end, nl, sep);
+ St->print(Out, *Mgr->StoreMgr, *Mgr->ConstraintMgr, beg, end, nl, sep);
}
//===----------------------------------------------------------------------===//