From 7affe151f5689b2d3547b8947c4099532c78a021 Mon Sep 17 00:00:00 2001 From: Jordan Rose Date: Thu, 6 Dec 2012 18:58:01 +0000 Subject: [PATCH] [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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169522 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../Core/PathSensitive/Environment.h | 10 --- .../Core/PathSensitive/ProgramState.h | 6 -- lib/StaticAnalyzer/Core/Environment.cpp | 63 +------------------ lib/StaticAnalyzer/Core/ExprEngine.cpp | 17 ++--- lib/StaticAnalyzer/Core/ProgramState.cpp | 17 ----- 5 files changed, 7 insertions(+), 106 deletions(-) diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/Environment.h b/include/clang/StaticAnalyzer/Core/PathSensitive/Environment.h index eb9bd85fe6..f3a582da04 100644 --- a/include/clang/StaticAnalyzer/Core/PathSensitive/Environment.h +++ b/include/clang/StaticAnalyzer/Core/PathSensitive/Environment.h @@ -33,9 +33,6 @@ class SValBuilder; /// other things. class EnvironmentEntry : public std::pair { - friend class EnvironmentManager; - EnvironmentEntry makeLocation() const; - public: EnvironmentEntry(const Stmt *s, const LocationContext *L); @@ -118,13 +115,6 @@ public: /// Bind a symbolic value to the given environment entry. 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, diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h b/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h index 15c77d6575..cb8dd08a24 100644 --- a/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h +++ b/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h @@ -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; diff --git a/lib/StaticAnalyzer/Core/Environment.cpp b/lib/StaticAnalyzer/Core/Environment.cpp index 60655435a0..b6c44bf5d6 100644 --- a/lib/StaticAnalyzer/Core/Environment.cpp +++ b/lib/StaticAnalyzer/Core/Environment.cpp @@ -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(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. @@ -203,8 +182,6 @@ EnvironmentManager::removeDeadBindings(Environment Env, // individually removing all the subexpression bindings (which will greatly // outnumber block-level expression bindings). Environment NewEnv = getInitialEnvironment(); - - SmallVector, 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())) { @@ -248,16 +216,6 @@ EnvironmentManager::removeDeadBindings(Environment Env, SymReaper.maybeDead(*SI); } } - - // Go through he deferred locations and add them to the new environment if - // the correspond Stmt* is in the map as well. - for (SmallVectorImpl >::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; @@ -265,30 +223,14 @@ EnvironmentManager::removeDeadBindings(Environment Env, 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 << ") "; diff --git a/lib/StaticAnalyzer/Core/ExprEngine.cpp b/lib/StaticAnalyzer/Core/ExprEngine.cpp index b0cd6487cb..ade44567f1 100644 --- a/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ b/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -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(location), LoadTy); - Bldr.generateNode(NodeEx, *NI, - state->bindExprAndLocation(BoundEx, LCtx, location, V), - tag, ProgramPoint::PostLoadKind); + V = state->getSVal(cast(location), LoadTy); } + + Bldr.generateNode(NodeEx, *NI, state->BindExpr(BoundEx, LCtx, V), tag, + ProgramPoint::PostLoadKind); } } diff --git a/lib/StaticAnalyzer/Core/ProgramState.cpp b/lib/StaticAnalyzer/Core/ProgramState.cpp index b368f2cef1..3b96cc899f 100644 --- a/lib/StaticAnalyzer/Core/ProgramState.cpp +++ b/lib/StaticAnalyzer/Core/ProgramState.cpp @@ -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, -- 2.40.0