forked from OSchip/llvm-project
[analyzer] Remove bindExprAndLocation, which does extra work for no gain.
This feature was probably intended to improve diagnostics, but was currently only used when dumping the Environment. It shows what location a given value was loaded from, e.g. when evaluating an LValueToRValue cast. llvm-svn: 169522
This commit is contained in:
parent
65ca2fb9e6
commit
047208027a
|
@ -33,9 +33,6 @@ class SValBuilder;
|
|||
/// other things.
|
||||
class EnvironmentEntry : public std::pair<const Stmt*,
|
||||
const StackFrameContext *> {
|
||||
friend class EnvironmentManager;
|
||||
EnvironmentEntry makeLocation() const;
|
||||
|
||||
public:
|
||||
EnvironmentEntry(const Stmt *s, const LocationContext *L);
|
||||
|
||||
|
@ -119,13 +116,6 @@ public:
|
|||
Environment bindExpr(Environment Env, const EnvironmentEntry &E, SVal V,
|
||||
bool Invalidate);
|
||||
|
||||
/// Bind the location 'location' and value 'V' to the specified
|
||||
/// environment entry.
|
||||
Environment bindExprAndLocation(Environment Env,
|
||||
const EnvironmentEntry &E,
|
||||
SVal location,
|
||||
SVal V);
|
||||
|
||||
Environment removeDeadBindings(Environment Env,
|
||||
SymbolReaper &SymReaper,
|
||||
ProgramStateRef state);
|
||||
|
|
|
@ -203,12 +203,6 @@ public:
|
|||
ProgramStateRef BindExpr(const Stmt *S, const LocationContext *LCtx,
|
||||
SVal V, bool Invalidate = true) const;
|
||||
|
||||
/// Create a new state by binding the value 'V' and location 'locaton' to the
|
||||
/// statement 'S' in the state's environment.
|
||||
ProgramStateRef bindExprAndLocation(const Stmt *S,
|
||||
const LocationContext *LCtx,
|
||||
SVal location, SVal V) const;
|
||||
|
||||
ProgramStateRef bindLoc(Loc location,
|
||||
SVal V,
|
||||
bool notifyChanges = true) const;
|
||||
|
|
|
@ -150,19 +150,6 @@ Environment EnvironmentManager::bindExpr(Environment Env,
|
|||
return Environment(F.add(Env.ExprBindings, E, V));
|
||||
}
|
||||
|
||||
EnvironmentEntry EnvironmentEntry::makeLocation() const {
|
||||
EnvironmentEntry Result = *this;
|
||||
reinterpret_cast<uintptr_t &>(Result.first) |= 0x1;
|
||||
return Result;
|
||||
}
|
||||
|
||||
Environment EnvironmentManager::bindExprAndLocation(Environment Env,
|
||||
const EnvironmentEntry &E,
|
||||
SVal location, SVal V) {
|
||||
return Environment(F.add(F.add(Env.ExprBindings, E.makeLocation(), location),
|
||||
E, V));
|
||||
}
|
||||
|
||||
namespace {
|
||||
class MarkLiveCallback : public SymbolVisitor {
|
||||
SymbolReaper &SymReaper;
|
||||
|
@ -179,14 +166,6 @@ public:
|
|||
};
|
||||
} // end anonymous namespace
|
||||
|
||||
// In addition to mapping from EnvironmentEntry - > SVals in the Environment,
|
||||
// we also maintain a mapping from EnvironmentEntry -> SVals (locations)
|
||||
// that were used during a load and store.
|
||||
static inline bool IsLocation(const EnvironmentEntry &E) {
|
||||
const Stmt *S = E.getStmt();
|
||||
return (bool) (((uintptr_t) S) & 0x1);
|
||||
}
|
||||
|
||||
// removeDeadBindings:
|
||||
// - Remove subexpression bindings.
|
||||
// - Remove dead block expression bindings.
|
||||
|
@ -204,8 +183,6 @@ EnvironmentManager::removeDeadBindings(Environment Env,
|
|||
// outnumber block-level expression bindings).
|
||||
Environment NewEnv = getInitialEnvironment();
|
||||
|
||||
SmallVector<std::pair<EnvironmentEntry, SVal>, 10> deferredLocations;
|
||||
|
||||
MarkLiveCallback CB(SymReaper);
|
||||
ScanReachableSymbols RSScaner(ST, CB);
|
||||
|
||||
|
@ -218,15 +195,6 @@ EnvironmentManager::removeDeadBindings(Environment Env,
|
|||
I != E; ++I) {
|
||||
|
||||
const EnvironmentEntry &BlkExpr = I.getKey();
|
||||
// For recorded locations (used when evaluating loads and stores), we
|
||||
// consider them live only when their associated normal expression is
|
||||
// also live.
|
||||
// NOTE: This assumes that loads/stores that evaluated to UnknownVal
|
||||
// still have an entry in the map.
|
||||
if (IsLocation(BlkExpr)) {
|
||||
deferredLocations.push_back(std::make_pair(BlkExpr, I.getData()));
|
||||
continue;
|
||||
}
|
||||
const SVal &X = I.getData();
|
||||
|
||||
if (SymReaper.isLive(BlkExpr.getStmt(), BlkExpr.getLocationContext())) {
|
||||
|
@ -249,46 +217,20 @@ EnvironmentManager::removeDeadBindings(Environment Env,
|
|||
}
|
||||
}
|
||||
|
||||
// Go through he deferred locations and add them to the new environment if
|
||||
// the correspond Stmt* is in the map as well.
|
||||
for (SmallVectorImpl<std::pair<EnvironmentEntry, SVal> >::iterator
|
||||
I = deferredLocations.begin(), E = deferredLocations.end(); I != E; ++I) {
|
||||
const EnvironmentEntry &En = I->first;
|
||||
const Stmt *S = (Stmt*) (((uintptr_t) En.getStmt()) & (uintptr_t) ~0x1);
|
||||
if (EBMapRef.lookup(EnvironmentEntry(S, En.getLocationContext())))
|
||||
EBMapRef = EBMapRef.add(En, I->second);
|
||||
}
|
||||
|
||||
NewEnv.ExprBindings = EBMapRef.asImmutableMap();
|
||||
return NewEnv;
|
||||
}
|
||||
|
||||
void Environment::print(raw_ostream &Out, const char *NL,
|
||||
const char *Sep) const {
|
||||
printAux(Out, false, NL, Sep);
|
||||
printAux(Out, true, NL, Sep);
|
||||
}
|
||||
|
||||
void Environment::printAux(raw_ostream &Out, bool printLocations,
|
||||
const char *NL,
|
||||
const char *Sep) const{
|
||||
|
||||
bool isFirst = true;
|
||||
|
||||
for (Environment::iterator I = begin(), E = end(); I != E; ++I) {
|
||||
const EnvironmentEntry &En = I.getKey();
|
||||
if (IsLocation(En)) {
|
||||
if (!printLocations)
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
if (printLocations)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isFirst) {
|
||||
Out << NL << NL
|
||||
<< (printLocations ? "Load/Store locations:" : "Expressions:")
|
||||
<< "Expressions:"
|
||||
<< NL;
|
||||
isFirst = false;
|
||||
} else {
|
||||
|
@ -296,9 +238,6 @@ void Environment::printAux(raw_ostream &Out, bool printLocations,
|
|||
}
|
||||
|
||||
const Stmt *S = En.getStmt();
|
||||
if (printLocations) {
|
||||
S = (Stmt*) (((uintptr_t) S) & ((uintptr_t) ~0x1));
|
||||
}
|
||||
|
||||
Out << " (" << (const void*) En.getLocationContext() << ','
|
||||
<< (const void*) S << ") ";
|
||||
|
|
|
@ -1736,20 +1736,15 @@ void ExprEngine::evalLoadCommon(ExplodedNodeSet &Dst,
|
|||
state = (*NI)->getState();
|
||||
const LocationContext *LCtx = (*NI)->getLocationContext();
|
||||
|
||||
if (location.isUnknown()) {
|
||||
// This is important. We must nuke the old binding.
|
||||
Bldr.generateNode(NodeEx, *NI,
|
||||
state->BindExpr(BoundEx, LCtx, UnknownVal()),
|
||||
tag, ProgramPoint::PostLoadKind);
|
||||
}
|
||||
else {
|
||||
SVal V = UnknownVal();
|
||||
if (location.isValid()) {
|
||||
if (LoadTy.isNull())
|
||||
LoadTy = BoundEx->getType();
|
||||
SVal V = state->getSVal(cast<Loc>(location), LoadTy);
|
||||
Bldr.generateNode(NodeEx, *NI,
|
||||
state->bindExprAndLocation(BoundEx, LCtx, location, V),
|
||||
tag, ProgramPoint::PostLoadKind);
|
||||
V = state->getSVal(cast<Loc>(location), LoadTy);
|
||||
}
|
||||
|
||||
Bldr.generateNode(NodeEx, *NI, state->BindExpr(BoundEx, LCtx, V), tag,
|
||||
ProgramPoint::PostLoadKind);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -268,23 +268,6 @@ ProgramStateRef ProgramState::BindExpr(const Stmt *S,
|
|||
return getStateManager().getPersistentState(NewSt);
|
||||
}
|
||||
|
||||
ProgramStateRef
|
||||
ProgramState::bindExprAndLocation(const Stmt *S, const LocationContext *LCtx,
|
||||
SVal location,
|
||||
SVal V) const {
|
||||
Environment NewEnv =
|
||||
getStateManager().EnvMgr.bindExprAndLocation(Env,
|
||||
EnvironmentEntry(S, LCtx),
|
||||
location, V);
|
||||
|
||||
if (NewEnv == Env)
|
||||
return this;
|
||||
|
||||
ProgramState NewSt = *this;
|
||||
NewSt.Env = NewEnv;
|
||||
return getStateManager().getPersistentState(NewSt);
|
||||
}
|
||||
|
||||
ProgramStateRef ProgramState::assumeInBound(DefinedOrUnknownSVal Idx,
|
||||
DefinedOrUnknownSVal UpperBound,
|
||||
bool Assumption,
|
||||
|
|
Loading…
Reference in New Issue