aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/BasicStore.cpp
diff options
context:
space:
mode:
authorZhongxing Xu <xuzhongxing@gmail.com>2008-10-16 06:09:51 +0000
committerZhongxing Xu <xuzhongxing@gmail.com>2008-10-16 06:09:51 +0000
commit6d69b5d82281992e981caa9bc038e3f6cac6594a (patch)
tree7f2af8d72bb34b24d631fb729774f4586d147fbc /lib/Analysis/BasicStore.cpp
parent5db4b3f3ed9f769d5b02c1d1ccc52bfd71fb9afb (diff)
This is the first step to build a better evaluation model for GRExprEngine. A
new VisitLValue method is added to replace the old VisitLVal. The semantics model becomes more explicit to separate rvalue evaluation from lvalue evaluation. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57627 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/BasicStore.cpp')
-rw-r--r--lib/Analysis/BasicStore.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/Analysis/BasicStore.cpp b/lib/Analysis/BasicStore.cpp
index 47e2905e02..f97f8b2c29 100644
--- a/lib/Analysis/BasicStore.cpp
+++ b/lib/Analysis/BasicStore.cpp
@@ -42,9 +42,12 @@ public:
virtual MemRegionManager& getRegionManager() { return MRMgr; }
+ // FIXME: Investigate what is using this. This method should be removed.
virtual LVal getLVal(const VarDecl* VD) {
return lval::MemRegionVal(MRMgr.getVarRegion(VD));
}
+
+ virtual RVal getLValue(const GRState* St, const Expr* Ex);
virtual Store
RemoveDeadBindings(Store store, Stmt* Loc, const LiveVariables& Live,
@@ -73,6 +76,35 @@ StoreManager* clang::CreateBasicStoreManager(GRStateManager& StMgr) {
return new BasicStoreManager(StMgr);
}
+// FIXME: replace ArrayOffset and FieldOffset with some region value.
+RVal BasicStoreManager::getLValue(const GRState* St, const Expr* Ex) {
+ if (const DeclRefExpr* DRE = dyn_cast<DeclRefExpr>(Ex)) {
+ const VarDecl* VD = cast<VarDecl>(DRE->getDecl());
+ QualType T = VD->getType();
+
+ // Array and struct variable have no lvalue.
+ assert(!T->isArrayType());
+
+ return lval::MemRegionVal(MRMgr.getVarRegion(VD));
+
+ } else if (const ArraySubscriptExpr* A = dyn_cast<ArraySubscriptExpr>(Ex)) {
+ const Expr* Base = A->getBase()->IgnoreParens();
+ const Expr* Idx = A->getIdx()->IgnoreParens();
+ RVal BaseV = StateMgr.GetRVal(St, Base);
+ RVal IdxV = StateMgr.GetRVal(St, Idx);
+ return lval::ArrayOffset::Make(StateMgr.getBasicVals(), BaseV, IdxV);
+
+ } else if (const MemberExpr* M = dyn_cast<MemberExpr>(Ex)) {
+ Expr* Base = M->getBase()->IgnoreParens();
+ RVal BaseV = StateMgr.GetRVal(St, Base);
+ return lval::FieldOffset::Make(StateMgr.getBasicVals(), BaseV,
+ M->getMemberDecl());
+ } else {
+ Ex->dump();
+ assert(0);
+ }
+}
+
RVal BasicStoreManager::GetRVal(Store St, LVal LV, QualType T) {
if (isa<UnknownVal>(LV))