[analyzer] Add getLocationContext to CheckerContext

CheckerContext::getPredecessor is only used to get to the LocationContext
half of the times.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143061 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h b/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
index f990095..b1aad7f 100644
--- a/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
+++ b/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
@@ -50,7 +50,7 @@
     return Eng.getStoreManager();
   }
 
-  ExplodedNode *&getPredecessor() { return Pred; }
+  ExplodedNode *getPredecessor() { return Pred; }
   const ProgramState *getState() { return Pred->getState(); }
 
   /// \brief Returns the number of times the current block has been visited
@@ -63,6 +63,10 @@
     return Eng.getContext();
   }
   
+  const LocationContext *getLocationContext() {
+    return Pred->getLocationContext();
+  }
+
   BugReporter &getBugReporter() {
     return Eng.getBugReporter();
   }
@@ -139,14 +143,14 @@
   }
 
 private:
-  ExplodedNode *addTransitionImpl(const ProgramState *state,
-                                 bool markAsSink,
-                                 ExplodedNode *pred = 0,
-                                 const ProgramPointTag *tag = 0) {
-    assert(state);
-    ExplodedNode *node = NB.generateNode(tag ? Location.withTag(tag) : Location,
-                                        state,
-                                        pred ? pred : Pred, markAsSink);
+  ExplodedNode *addTransitionImpl(const ProgramState *State,
+                                 bool MarkAsSink,
+                                 ExplodedNode *P = 0,
+                                 const ProgramPointTag *Tag = 0) {
+    assert(State);
+    ExplodedNode *node = NB.generateNode(Tag ? Location.withTag(Tag) : Location,
+                                        State,
+                                        P ? P : Pred, MarkAsSink);
     return node;
   }
 };
diff --git a/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp b/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
index d00ef59..4ad7cc9 100644
--- a/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
@@ -57,8 +57,7 @@
     // FIXME: Refactor into StoreManager itself?
     MemRegionManager& RM = C.getStoreManager().getRegionManager();
     const AllocaRegion* R =
-      RM.getAllocaRegion(CE, C.getCurrentBlockCount(),
-                         C.getPredecessor()->getLocationContext());
+      RM.getAllocaRegion(CE, C.getCurrentBlockCount(), C.getLocationContext());
 
     // Set the extent of the region in bytes. This enables us to use the
     // SVal of the argument directly. If we save the extent in bits, we
diff --git a/lib/StaticAnalyzer/Checkers/CStringChecker.cpp b/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
index 1795b82..4299a12 100644
--- a/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -1733,7 +1733,7 @@
     if (!isa<StringLiteral>(Init))
       continue;
 
-    Loc VarLoc = state->getLValue(D, C.getPredecessor()->getLocationContext());
+    Loc VarLoc = state->getLValue(D, C.getLocationContext());
     const MemRegion *MR = VarLoc.getAsRegion();
     if (!MR)
       continue;
diff --git a/lib/StaticAnalyzer/Checkers/IteratorsChecker.cpp b/lib/StaticAnalyzer/Checkers/IteratorsChecker.cpp
index a064a65..ab3242b 100644
--- a/lib/StaticAnalyzer/Checkers/IteratorsChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/IteratorsChecker.cpp
@@ -395,8 +395,7 @@
 // with the same tag.
 void IteratorsChecker::checkExpr(CheckerContext &C, const Expr *E) const {
   const ProgramState *state = C.getState();
-  const MemRegion *MR = getRegion(state, E,
-                   C.getPredecessor()->getLocationContext());
+  const MemRegion *MR = getRegion(state, E, C.getLocationContext());
   if (!MR)
     return;
 
@@ -466,7 +465,7 @@
 void IteratorsChecker::checkPreStmt(const CXXOperatorCallExpr *OCE,
                                     CheckerContext &C) const
 {
-  const LocationContext *LC = C.getPredecessor()->getLocationContext();
+  const LocationContext *LC = C.getLocationContext();
   const ProgramState *state = C.getState();
   OverloadedOperatorKind Kind = OCE->getOperator();
   if (Kind == OO_Equal) {
@@ -525,7 +524,7 @@
 
   // Get the MemRegion associated with the iterator and mark it as Undefined.
   const ProgramState *state = C.getState();
-  Loc VarLoc = state->getLValue(VD, C.getPredecessor()->getLocationContext());
+  Loc VarLoc = state->getLValue(VD, C.getLocationContext());
   const MemRegion *MR = VarLoc.getAsRegion();
   if (!MR)
     return;
@@ -545,8 +544,7 @@
           E = M->GetTemporaryExpr();
         if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E))
           InitEx = ICE->getSubExpr();
-        state = handleAssign(state, MR, InitEx,
-                                  C.getPredecessor()->getLocationContext());
+        state = handleAssign(state, MR, InitEx, C.getLocationContext());
       }
     }
   }
diff --git a/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp b/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
index 5678998..870e38e 100644
--- a/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
@@ -198,7 +198,7 @@
 
 static QualType parameterTypeFromSVal(SVal val, CheckerContext &C) {
   const StackFrameContext *
-    SFC = C.getPredecessor()->getLocationContext()->getCurrentStackFrame();
+    SFC = C.getLocationContext()->getCurrentStackFrame();
   if (const loc::MemRegionVal* X = dyn_cast<loc::MemRegionVal>(&val)) {
     const MemRegion* R = X->getRegion();
     if (const VarRegion *VR = R->getAs<VarRegion>())
diff --git a/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp b/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
index 5f062a7..8f9f7d5 100644
--- a/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
@@ -2501,7 +2501,7 @@
   // via captured variables, even though captured variables result in a copy
   // and in implicit increment/decrement of a retain count.
   SmallVector<const MemRegion*, 10> Regions;
-  const LocationContext *LC = C.getPredecessor()->getLocationContext();
+  const LocationContext *LC = C.getLocationContext();
   MemRegionManager &MemMgr = C.getSValBuilder().getRegionManager();
 
   for ( ; I != E; ++I) {
@@ -2681,7 +2681,7 @@
   // Evaluate the effect on the message receiver.
   bool ReceiverIsTracked = false;
   if (!hasErr && CallOrMsg.isObjCMessage()) {
-    const LocationContext *LC = C.getPredecessor()->getLocationContext();
+    const LocationContext *LC = C.getLocationContext();
     SVal Receiver = CallOrMsg.getInstanceMessageReceiver(LC);
     if (SymbolRef Sym = Receiver.getAsLocSymbol()) {
       if (const RefVal *T = state->get<RefBindings>(Sym)) {
diff --git a/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp b/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
index 9d5660c..0d3059e 100644
--- a/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
@@ -150,7 +150,7 @@
 
     CallBack(CheckerContext &CC) :
       Ctx(CC),
-      CurSFC(CC.getPredecessor()->getLocationContext()->getCurrentStackFrame())
+      CurSFC(CC.getLocationContext()->getCurrentStackFrame())
     {}
     
     bool HandleBinding(StoreManager &SMgr, Store store,
diff --git a/lib/StaticAnalyzer/Checkers/UndefCapturedBlockVarChecker.cpp b/lib/StaticAnalyzer/Checkers/UndefCapturedBlockVarChecker.cpp
index 2aebed9..82c9fd4 100644
--- a/lib/StaticAnalyzer/Checkers/UndefCapturedBlockVarChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/UndefCapturedBlockVarChecker.cpp
@@ -72,7 +72,7 @@
       continue;
 
     // Get the VarRegion associated with VD in the local stack frame.
-    const LocationContext *LC = C.getPredecessor()->getLocationContext();
+    const LocationContext *LC = C.getLocationContext();
     VR = C.getSValBuilder().getRegionManager().getVarRegion(VD, LC);
     SVal VRVal = state->getSVal(VR);
 
diff --git a/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp b/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
index b34b97c..969a896 100644
--- a/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
@@ -117,7 +117,7 @@
                                               cast<NonLoc>(EleSizeVal), SizeTy);
 
   // Finally, assume that the array's extent matches the given size.
-  const LocationContext *LC = C.getPredecessor()->getLocationContext();
+  const LocationContext *LC = C.getLocationContext();
   DefinedOrUnknownSVal Extent =
     state->getRegion(VD, LC)->getExtent(svalBuilder);
   DefinedOrUnknownSVal ArraySize = cast<DefinedOrUnknownSVal>(ArraySizeVal);