summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/include/clang/Analysis/PathSensitive/Environment.h31
-rw-r--r--clang/include/clang/Analysis/PathSensitive/GRState.h29
-rw-r--r--clang/lib/Analysis/Environment.cpp42
-rw-r--r--clang/lib/Analysis/GRState.cpp9
4 files changed, 58 insertions, 53 deletions
diff --git a/clang/include/clang/Analysis/PathSensitive/Environment.h b/clang/include/clang/Analysis/PathSensitive/Environment.h
index 7b1ae9f8817..7a0c88279cf 100644
--- a/clang/include/clang/Analysis/PathSensitive/Environment.h
+++ b/clang/include/clang/Analysis/PathSensitive/Environment.h
@@ -1,4 +1,4 @@
-//== Environment.h - Map from Expr* to Locations/Values ---------*- C++ -*--==//
+//== Environment.h - Map from Stmt* to Locations/Values ---------*- C++ -*--==//
//
// The LLVM Compiler Infrastructure
//
@@ -36,7 +36,7 @@ private:
friend class EnvironmentManager;
// Type definitions.
- typedef llvm::ImmutableMap<Expr*,SVal> BindingsTy;
+ typedef llvm::ImmutableMap<Stmt*,SVal> BindingsTy;
// Data.
BindingsTy SubExprBindings;
@@ -55,28 +55,25 @@ public:
beb_iterator beb_begin() const { return BlkExprBindings.begin(); }
beb_iterator beb_end() const { return BlkExprBindings.end(); }
- SVal LookupSubExpr(Expr* E) const {
- const SVal* X = SubExprBindings.lookup(E);
+ SVal LookupSubExpr(Stmt* E) const {
+ const SVal* X = SubExprBindings.lookup(cast<Expr>(E));
return X ? *X : UnknownVal();
}
- SVal LookupBlkExpr(Expr* E) const {
+ SVal LookupBlkExpr(Stmt* E) const {
const SVal* X = BlkExprBindings.lookup(E);
return X ? *X : UnknownVal();
}
- SVal LookupExpr(Expr* E) const {
+ SVal LookupExpr(Stmt* E) const {
const SVal* X = SubExprBindings.lookup(E);
if (X) return *X;
X = BlkExprBindings.lookup(E);
return X ? *X : UnknownVal();
}
- SVal GetSVal(Expr* Ex, BasicValueFactory& BasicVals) const;
- SVal GetSVal(const Expr* Ex, BasicValueFactory& BasicVals) const {
- return GetSVal(const_cast<Expr*>(Ex), BasicVals);
- }
- SVal GetBlkExprSVal(Expr* Ex, BasicValueFactory& BasicVals) const;
+ SVal GetSVal(Stmt* Ex, BasicValueFactory& BasicVals) const;
+ SVal GetBlkExprSVal(Stmt* Ex, BasicValueFactory& BasicVals) const;
/// Profile - Profile the contents of an Environment object for use
/// in a FoldingSet.
@@ -108,23 +105,23 @@ public:
~EnvironmentManager() {}
/// RemoveBlkExpr - Return a new environment object with the same bindings as
- /// the provided environment except with any bindings for the provided Expr*
+ /// the provided environment except with any bindings for the provided Stmt*
/// removed. This method only removes bindings for block-level expressions.
/// Using this method on a non-block level expression will return the
/// same environment object.
- Environment RemoveBlkExpr(const Environment& Env, Expr* E) {
+ Environment RemoveBlkExpr(const Environment& Env, Stmt* E) {
return Environment(Env.SubExprBindings, F.Remove(Env.BlkExprBindings, E));
}
- Environment RemoveSubExpr(const Environment& Env, Expr* E) {
+ Environment RemoveSubExpr(const Environment& Env, Stmt* E) {
return Environment(F.Remove(Env.SubExprBindings, E), Env.BlkExprBindings);
}
- Environment AddBlkExpr(const Environment& Env, Expr* E, SVal V) {
+ Environment AddBlkExpr(const Environment& Env, Stmt* E, SVal V) {
return Environment(Env.SubExprBindings, F.Add(Env.BlkExprBindings, E, V));
}
- Environment AddSubExpr(const Environment& Env, Expr* E, SVal V) {
+ Environment AddSubExpr(const Environment& Env, Stmt* E, SVal V) {
return Environment(F.Add(Env.SubExprBindings, E, V), Env.BlkExprBindings);
}
@@ -139,7 +136,7 @@ public:
return Environment(F.GetEmptyMap(), F.GetEmptyMap());
}
- Environment BindExpr(const Environment& Env, Expr* E, SVal V,
+ Environment BindExpr(const Environment& Env, Stmt* E, SVal V,
bool isBlkExpr, bool Invalidate);
Environment RemoveDeadBindings(Environment Env, Stmt* Loc,
diff --git a/clang/include/clang/Analysis/PathSensitive/GRState.h b/clang/include/clang/Analysis/PathSensitive/GRState.h
index 6b68425cb89..0a40998e399 100644
--- a/clang/include/clang/Analysis/PathSensitive/GRState.h
+++ b/clang/include/clang/Analysis/PathSensitive/GRState.h
@@ -329,7 +329,7 @@ public:
typedef StoreManager::DeadSymbolsTy DeadSymbolsTy;
- const GRState* BindDecl(const GRState* St, const VarDecl* VD, Expr* Ex,
+ const GRState* BindDecl(const GRState* St, const VarDecl* VD, SVal* IVal,
unsigned Count);
/// BindCompoundLiteral - Return the state that has the bindings currently
@@ -391,19 +391,19 @@ public:
// Methods that query & manipulate the Environment.
- SVal GetSVal(const GRState* St, Expr* Ex) {
+ SVal GetSVal(const GRState* St, Stmt* Ex) {
return St->getEnvironment().GetSVal(Ex, BasicVals);
}
- SVal GetSVal(const GRState* St, const Expr* Ex) {
- return St->getEnvironment().GetSVal(Ex, BasicVals);
+ SVal GetSVal(const GRState* St, const Stmt* Ex) {
+ return St->getEnvironment().GetSVal(const_cast<Stmt*>(Ex), BasicVals);
}
- SVal GetBlkExprSVal(const GRState* St, Expr* Ex) {
+ SVal GetBlkExprSVal(const GRState* St, Stmt* Ex) {
return St->getEnvironment().GetBlkExprSVal(Ex, BasicVals);
}
- const GRState* BindExpr(const GRState* St, Expr* Ex, SVal V,
+ const GRState* BindExpr(const GRState* St, Stmt* Ex, SVal V,
bool isBlkExpr, bool Invalidate) {
const Environment& OldEnv = St->getEnvironment();
@@ -417,7 +417,7 @@ public:
return getPersistentState(NewSt);
}
- const GRState* BindExpr(const GRState* St, Expr* Ex, SVal V,
+ const GRState* BindExpr(const GRState* St, Stmt* Ex, SVal V,
bool Invalidate = true) {
bool isBlkExpr = false;
@@ -562,20 +562,29 @@ public:
return Mgr->GetSVal(St, R);
}
- GRStateRef SetSVal(Expr* Ex, SVal V, bool isBlkExpr, bool Invalidate) {
+ GRStateRef BindExpr(Stmt* Ex, SVal V, bool isBlkExpr, bool Invalidate) {
return GRStateRef(Mgr->BindExpr(St, Ex, V, isBlkExpr, Invalidate), *Mgr);
}
- GRStateRef SetSVal(Expr* Ex, SVal V, bool Invalidate = true) {
+ GRStateRef BindExpr(Stmt* Ex, SVal V, bool Invalidate = true) {
return GRStateRef(Mgr->BindExpr(St, Ex, V, Invalidate), *Mgr);
}
+
+ GRStateRef BindDecl(const VarDecl* VD, SVal* InitVal, unsigned Count) {
+ return GRStateRef(Mgr->BindDecl(St, VD, InitVal, Count), *Mgr);
+ }
- GRStateRef SetSVal(Loc LV, SVal V) {
+ GRStateRef BindLoc(Loc LV, SVal V) {
GRState StImpl = *St;
Mgr->BindLoc(StImpl, LV, V);
return GRStateRef(Mgr->getPersistentState(StImpl), *Mgr);
}
+ GRStateRef BindLoc(SVal LV, SVal V) {
+ if (!isa<Loc>(LV)) return *this;
+ return BindLoc(cast<Loc>(LV), V);
+ }
+
GRStateRef Unbind(Loc LV) {
return GRStateRef(Mgr->Unbind(St, LV), *Mgr);
}
diff --git a/clang/lib/Analysis/Environment.cpp b/clang/lib/Analysis/Environment.cpp
index 0effe3ae58f..a67965e35a1 100644
--- a/clang/lib/Analysis/Environment.cpp
+++ b/clang/lib/Analysis/Environment.cpp
@@ -1,4 +1,4 @@
-//== Environment.cpp - Map from Expr* to Locations/Values -------*- C++ -*--==//
+//== Environment.cpp - Map from Stmt* to Locations/Values -------*- C++ -*--==//
//
// The LLVM Compiler Infrastructure
//
@@ -18,7 +18,7 @@
using namespace clang;
-SVal Environment::GetSVal(Expr* E, BasicValueFactory& BasicVals) const {
+SVal Environment::GetSVal(Stmt* E, BasicValueFactory& BasicVals) const {
for (;;) {
@@ -58,7 +58,7 @@ SVal Environment::GetSVal(Expr* E, BasicValueFactory& BasicVals) const {
break;
}
- // Handle all other Expr* using a lookup.
+ // Handle all other Stmt* using a lookup.
default:
break;
@@ -70,26 +70,30 @@ SVal Environment::GetSVal(Expr* E, BasicValueFactory& BasicVals) const {
return LookupExpr(E);
}
-SVal Environment::GetBlkExprSVal(Expr* E, BasicValueFactory& BasicVals) const {
+SVal Environment::GetBlkExprSVal(Stmt* E, BasicValueFactory& BasicVals) const {
- E = E->IgnoreParens();
-
- switch (E->getStmtClass()) {
- case Stmt::CharacterLiteralClass: {
- CharacterLiteral* C = cast<CharacterLiteral>(E);
- return NonLoc::MakeVal(BasicVals, C->getValue(), C->getType());
- }
-
- case Stmt::IntegerLiteralClass: {
- return NonLoc::MakeVal(BasicVals, cast<IntegerLiteral>(E));
+ while (1) {
+ switch (E->getStmtClass()) {
+ case Stmt::ParenExprClass:
+ E = cast<ParenExpr>(E)->getSubExpr();
+ continue;
+
+ case Stmt::CharacterLiteralClass: {
+ CharacterLiteral* C = cast<CharacterLiteral>(E);
+ return NonLoc::MakeVal(BasicVals, C->getValue(), C->getType());
+ }
+
+ case Stmt::IntegerLiteralClass: {
+ return NonLoc::MakeVal(BasicVals, cast<IntegerLiteral>(E));
+ }
+
+ default:
+ return LookupBlkExpr(E);
}
-
- default:
- return LookupBlkExpr(E);
}
}
-Environment EnvironmentManager::BindExpr(const Environment& Env, Expr* E,SVal V,
+Environment EnvironmentManager::BindExpr(const Environment& Env, Stmt* E,SVal V,
bool isBlkExpr, bool Invalidate) {
assert (E);
@@ -115,7 +119,7 @@ EnvironmentManager::RemoveDeadBindings(Environment Env, Stmt* Loc,
// Iterate over the block-expr bindings.
for (Environment::beb_iterator I = Env.beb_begin(), E = Env.beb_end();
I != E; ++I) {
- Expr* BlkExpr = I.getKey();
+ Stmt* BlkExpr = I.getKey();
if (Liveness.isLive(Loc, BlkExpr)) {
SVal X = I.getData();
diff --git a/clang/lib/Analysis/GRState.cpp b/clang/lib/Analysis/GRState.cpp
index 57f9c6b2793..dd296e06765 100644
--- a/clang/lib/Analysis/GRState.cpp
+++ b/clang/lib/Analysis/GRState.cpp
@@ -73,15 +73,10 @@ const GRState* GRStateManager::BindLoc(const GRState* St, Loc LV, SVal V) {
}
const GRState* GRStateManager::BindDecl(const GRState* St, const VarDecl* VD,
- Expr* Ex, unsigned Count) {
+ SVal* InitVal, unsigned Count) {
Store OldStore = St->getStore();
- Store NewStore;
+ Store NewStore = StoreMgr->BindDecl(OldStore, VD, InitVal, Count);
- if (Ex)
- NewStore = StoreMgr->BindDecl(OldStore, VD, Ex, GetSVal(St, Ex), Count);
- else
- NewStore = StoreMgr->BindDecl(OldStore, VD, Ex);
-
if (NewStore == OldStore)
return St;
OpenPOWER on IntegriCloud