[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
diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/Environment.h b/include/clang/StaticAnalyzer/Core/PathSensitive/Environment.h
index eb9bd85..f3a582d 100644
--- a/include/clang/StaticAnalyzer/Core/PathSensitive/Environment.h
+++ b/include/clang/StaticAnalyzer/Core/PathSensitive/Environment.h
@@ -33,9 +33,6 @@
 /// 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);
 
@@ -118,13 +115,6 @@
   /// 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 15c77d6..cb8dd08 100644
--- a/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
+++ b/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
@@ -203,12 +203,6 @@
   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 6065543..b6c44bf 100644
--- a/lib/StaticAnalyzer/Core/Environment.cpp
+++ b/lib/StaticAnalyzer/Core/Environment.cpp
@@ -150,19 +150,6 @@
   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 @@
 };
 } // 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 @@
   // individually removing all the subexpression bindings (which will greatly
   // 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 @@
        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 @@
         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<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;
@@ -265,30 +223,14 @@
 
 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 @@
     }
     
     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 b0cd648..ade4456 100644
--- a/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ b/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1736,20 +1736,15 @@
     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);
   }
 }
 
diff --git a/lib/StaticAnalyzer/Core/ProgramState.cpp b/lib/StaticAnalyzer/Core/ProgramState.cpp
index b368f2c..3b96cc8 100644
--- a/lib/StaticAnalyzer/Core/ProgramState.cpp
+++ b/lib/StaticAnalyzer/Core/ProgramState.cpp
@@ -268,23 +268,6 @@
   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,