[analyzer] Refactor PathDiagnosticLocation: Make PathDiagnosticLocation(SourceLocation...) private. Most of the effort here goes to making BugReport refer to a PathDiagnosticLocation instead of FullSourceLocation. 

(Another step closer to the goal of having Diagnostics which can recover from invalid SourceLocations.)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140182 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp b/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
index ed2a859..7791d9d 100644
--- a/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
@@ -1756,7 +1756,6 @@
   };
 
   class CFRefLeakReport : public CFRefReport {
-    SourceLocation AllocSite;
     const MemRegion* AllocBinding;
 
   public:
@@ -1764,7 +1763,10 @@
                     const SummaryLogTy &Log, ExplodedNode *n, SymbolRef sym,
                     ExprEngine &Eng);
 
-    SourceLocation getLocation() const { return AllocSite; }
+    PathDiagnosticLocation getLocation(const SourceManager &SM) const {
+      assert(Location.isValid());
+      return Location;
+    }
   };
 } // end anonymous namespace
 
@@ -2219,18 +2221,20 @@
   // same SourceLocation.
   const ExplodedNode *AllocNode = 0;
 
+  const SourceManager& SMgr = Eng.getContext().getSourceManager();
+
   llvm::tie(AllocNode, AllocBinding) =  // Set AllocBinding.
     GetAllocationSite(Eng.getStateManager(), getErrorNode(), sym);
 
   // Get the SourceLocation for the allocation site.
   ProgramPoint P = AllocNode->getLocation();
-  AllocSite = cast<PostStmt>(P).getStmt()->getLocStart();
-
+  const Stmt *AllocStmt = cast<PostStmt>(P).getStmt();
+  Location = PathDiagnosticLocation::createBegin(AllocStmt, SMgr,
+                                                  n->getLocationContext());
   // Fill in the description of the bug.
   Description.clear();
   llvm::raw_string_ostream os(Description);
-  SourceManager& SMgr = Eng.getContext().getSourceManager();
-  unsigned AllocLine = SMgr.getExpansionLineNumber(AllocSite);
+  unsigned AllocLine = SMgr.getExpansionLineNumber(AllocStmt->getLocStart());
   os << "Potential leak ";
   if (GCEnabled)
     os << "(when using garbage collection) ";