aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhongxing Xu <xuzhongxing@gmail.com>2008-10-25 14:18:57 +0000
committerZhongxing Xu <xuzhongxing@gmail.com>2008-10-25 14:18:57 +0000
commit143bf82ac5afba0757e6817a2c2bb970c20b32d3 (patch)
tree80a8fac0c26c37e510a315597d56a98cb3b69aa7
parente9f4e5420895a75dd788e9891921e7781c1823b9 (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
-rw-r--r--include/clang/Analysis/PathSensitive/GRState.h5
-rw-r--r--include/clang/Analysis/PathSensitive/Store.h4
-rw-r--r--lib/Analysis/BasicStore.cpp6
-rw-r--r--lib/Analysis/Environment.cpp11
-rw-r--r--lib/Analysis/GRExprEngine.cpp7
-rw-r--r--lib/Analysis/RegionStore.cpp19
6 files changed, 41 insertions, 11 deletions
diff --git a/include/clang/Analysis/PathSensitive/GRState.h b/include/clang/Analysis/PathSensitive/GRState.h
index b599301c17..d9b058ce84 100644
--- a/include/clang/Analysis/PathSensitive/GRState.h
+++ b/include/clang/Analysis/PathSensitive/GRState.h
@@ -355,6 +355,11 @@ public:
SVal GetLValue(const GRState* St, const VarDecl* D) {
return StoreMgr->getLValueVar(St, D);
}
+
+ // Get the lvalue for a StringLiteral.
+ SVal GetLValue(const GRState* St, const StringLiteral* E) {
+ return StoreMgr->getLValueString(St, E);
+ }
// Get the lvalue for an ivar reference.
SVal GetLValue(const GRState* St, const ObjCIvarDecl* D, SVal Base) {
diff --git a/include/clang/Analysis/PathSensitive/Store.h b/include/clang/Analysis/PathSensitive/Store.h
index aa3b5e791b..7610c54e1b 100644
--- a/include/clang/Analysis/PathSensitive/Store.h
+++ b/include/clang/Analysis/PathSensitive/Store.h
@@ -50,7 +50,9 @@ public:
virtual Store getInitialStore() = 0;
virtual MemRegionManager& getRegionManager() = 0;
- virtual SVal getLValueVar(const GRState* St, const VarDecl* VD) = 0;
+ virtual SVal getLValueVar(const GRState* St, const VarDecl* VD) = 0;
+
+ virtual SVal getLValueString(const GRState* St, const StringLiteral* S) = 0;
virtual SVal getLValueIvar(const GRState* St, const ObjCIvarDecl* D,
SVal Base) = 0;
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);