diff options
author | Zhongxing Xu <xuzhongxing@gmail.com> | 2008-10-25 14:18:57 +0000 |
---|---|---|
committer | Zhongxing Xu <xuzhongxing@gmail.com> | 2008-10-25 14:18:57 +0000 |
commit | 143bf82ac5afba0757e6817a2c2bb970c20b32d3 (patch) | |
tree | 80a8fac0c26c37e510a315597d56a98cb3b69aa7 /lib/Analysis | |
parent | e9f4e5420895a75dd788e9891921e7781c1823b9 (diff) |
Add code for get the lvalue for string literals. Now we return a StringRegion
for StringLiteral lvalue evaluation, instead of directly returning a
loc::StringLiteralVal by the Environment.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58138 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis')
-rw-r--r-- | lib/Analysis/BasicStore.cpp | 6 | ||||
-rw-r--r-- | lib/Analysis/Environment.cpp | 11 | ||||
-rw-r--r-- | lib/Analysis/GRExprEngine.cpp | 7 | ||||
-rw-r--r-- | lib/Analysis/RegionStore.cpp | 19 |
4 files changed, 33 insertions, 10 deletions
diff --git a/lib/Analysis/BasicStore.cpp b/lib/Analysis/BasicStore.cpp index e12b9ea0a1..67d919a6d6 100644 --- a/lib/Analysis/BasicStore.cpp +++ b/lib/Analysis/BasicStore.cpp @@ -47,6 +47,7 @@ public: } SVal getLValueVar(const GRState* St, const VarDecl* VD); + SVal getLValueString(const GRState* St, const StringLiteral* S); SVal getLValueIvar(const GRState* St, const ObjCIvarDecl* D, SVal Base); SVal getLValueField(const GRState* St, SVal Base, const FieldDecl* D); SVal getLValueElement(const GRState* St, SVal Base, SVal Offset); @@ -88,6 +89,11 @@ StoreManager* clang::CreateBasicStoreManager(GRStateManager& StMgr) { SVal BasicStoreManager::getLValueVar(const GRState* St, const VarDecl* VD) { return loc::MemRegionVal(MRMgr.getVarRegion(VD)); } + +SVal BasicStoreManager::getLValueString(const GRState* St, + const StringLiteral* S) { + return loc::MemRegionVal(MRMgr.getStringRegion(S)); +} SVal BasicStoreManager::getLValueIvar(const GRState* St, const ObjCIvarDecl* D, SVal Base) { diff --git a/lib/Analysis/Environment.cpp b/lib/Analysis/Environment.cpp index a9afa6d86b..f220ee7a12 100644 --- a/lib/Analysis/Environment.cpp +++ b/lib/Analysis/Environment.cpp @@ -42,13 +42,10 @@ SVal Environment::GetSVal(Expr* E, BasicValueFactory& BasicVals) const { return NonLoc::MakeVal(BasicVals, cast<IntegerLiteral>(E)); } - case Stmt::StringLiteralClass: - return Loc::MakeVal(cast<StringLiteral>(E)); - - // Casts where the source and target type are the same - // are no-ops. We blast through these to get the descendant - // subexpression that has a value. - + // Casts where the source and target type are the same + // are no-ops. We blast through these to get the descendant + // subexpression that has a value. + case Stmt::ImplicitCastExprClass: case Stmt::ExplicitCastExprClass: { CastExpr* C = cast<CastExpr>(E); diff --git a/lib/Analysis/GRExprEngine.cpp b/lib/Analysis/GRExprEngine.cpp index ae1db6c462..7d60dec9b8 100644 --- a/lib/Analysis/GRExprEngine.cpp +++ b/lib/Analysis/GRExprEngine.cpp @@ -444,6 +444,13 @@ void GRExprEngine::VisitLValue(Expr* Ex, NodeTy* Pred, NodeSet& Dst) { // have "locations" in the sense that we can take their address. Dst.Add(Pred); return; + + case Stmt::StringLiteralClass: { + const GRState* St = GetState(Pred); + SVal V = StateMgr.GetLValue(St, cast<StringLiteral>(Ex)); + MakeNode(Dst, Ex, Pred, SetSVal(St, Ex, V)); + return; + } default: // Arbitrary subexpressions can return aggregate temporaries that diff --git a/lib/Analysis/RegionStore.cpp b/lib/Analysis/RegionStore.cpp index e2b6b13e64..eabe462cc7 100644 --- a/lib/Analysis/RegionStore.cpp +++ b/lib/Analysis/RegionStore.cpp @@ -46,6 +46,8 @@ public: return Retrieve(St, loc::MemRegionVal(R)); } + SVal getLValueString(const GRState* St, const StringLiteral* S); + SVal getLValueVar(const GRState* St, const VarDecl* VD); SVal getLValueIvar(const GRState* St, const ObjCIvarDecl* D, SVal Base); @@ -110,6 +112,11 @@ StoreManager* clang::CreateRegionStoreManager(GRStateManager& StMgr) { return new RegionStoreManager(StMgr); } +SVal RegionStoreManager::getLValueString(const GRState* St, + const StringLiteral* S) { + return loc::MemRegionVal(MRMgr.getStringRegion(S)); +} + SVal RegionStoreManager::getLValueVar(const GRState* St, const VarDecl* VD) { return loc::MemRegionVal(MRMgr.getVarRegion(VD)); } @@ -188,6 +195,15 @@ SVal RegionStoreManager::getLValueElement(const GRState* St, SVal RegionStoreManager::ArrayToPointer(SVal Array) { const MemRegion* ArrayR = cast<loc::MemRegionVal>(&Array)->getRegion(); + BasicValueFactory& BasicVals = StateMgr.getBasicVals(); + + if (const StringRegion* StringR = dyn_cast<StringRegion>(ArrayR)) { + // FIXME: Find a better way to get bit width. + nonloc::ConcreteInt Idx(BasicVals.getValue(0, 32, false)); + ElementRegion* ER = MRMgr.getElementRegion(Idx, ArrayR); + + return loc::MemRegionVal(ER); + } const Decl* D = cast<DeclRegion>(ArrayR)->getDecl(); @@ -201,12 +217,9 @@ SVal RegionStoreManager::ArrayToPointer(SVal Array) { if (const ConstantArrayType* CAT = dyn_cast<ConstantArrayType>(ArrayTy.getTypePtr())) { - - BasicValueFactory& BasicVals = StateMgr.getBasicVals(); nonloc::ConcreteInt Idx(BasicVals.getValue(0, CAT->getSize().getBitWidth(), false)); - ElementRegion* ER = MRMgr.getElementRegion(Idx, ArrayR); return loc::MemRegionVal(ER); |