Associate the macro arguments location map with a FileID instead
of a ContentCache, since multiple FileIDs can have the same ContentCache
but the expanded macro arguments locations will be different.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140521 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Basic/SourceManager.cpp b/lib/Basic/SourceManager.cpp
index 410d4df..0c27e99 100644
--- a/lib/Basic/SourceManager.cpp
+++ b/lib/Basic/SourceManager.cpp
@@ -39,7 +39,6 @@
 ContentCache::~ContentCache() {
   if (shouldFreeBuffer())
     delete Buffer.getPointer();
-  delete MacroArgsCache;
 }
 
 /// getSizeBytesMapped - Returns the number of bytes actually mapped for this
@@ -389,6 +388,11 @@
   }
   
   delete FakeBufferForRecovery;
+
+  for (llvm::DenseMap<FileID, MacroArgsMap *>::iterator
+         I = MacroArgsCacheMap.begin(),E = MacroArgsCacheMap.end(); I!=E; ++I) {
+    delete I->second;
+  }
 }
 
 void SourceManager::clearIDTables() {
@@ -1503,13 +1507,13 @@
 ///     0   -> SourceLocation()
 ///     100 -> Expanded macro arg location
 ///     110 -> SourceLocation()
-void SourceManager::computeMacroArgsCache(ContentCache *Content,
+void SourceManager::computeMacroArgsCache(MacroArgsMap *&CachePtr,
                                           FileID FID) const {
-  assert(!Content->MacroArgsCache);
   assert(!FID.isInvalid());
+  assert(!CachePtr);
 
-  Content->MacroArgsCache = new ContentCache::MacroArgsMap();
-  ContentCache::MacroArgsMap &MacroArgsCache = *Content->MacroArgsCache;
+  CachePtr = new MacroArgsMap();
+  MacroArgsMap &MacroArgsCache = *CachePtr;
   // Initially no macro argument chunk is present.
   MacroArgsCache.insert(std::make_pair(0, SourceLocation()));
 
@@ -1566,7 +1570,7 @@
     // previous chunks, we only need to find where the ending of the new macro
     // chunk is mapped to and update the map with new begin/end mappings.
 
-    ContentCache::MacroArgsMap::iterator I= MacroArgsCache.upper_bound(EndOffs);
+    MacroArgsMap::iterator I = MacroArgsCache.upper_bound(EndOffs);
     --I;
     SourceLocation EndOffsMappedLoc = I->second;
     MacroArgsCache[BeginOffs] = SourceLocation::getMacroLoc(Entry.getOffset());
@@ -1594,15 +1598,12 @@
   if (FID.isInvalid())
     return Loc;
 
-  ContentCache *Content
-    = const_cast<ContentCache *>(getSLocEntry(FID).getFile().getContentCache());
-  if (!Content->MacroArgsCache)
-    computeMacroArgsCache(Content, FID);
+  MacroArgsMap *&MacroArgsCache = MacroArgsCacheMap[FID];
+  if (!MacroArgsCache)
+    computeMacroArgsCache(MacroArgsCache, FID);
 
-  assert(Content->MacroArgsCache);
-  assert(!Content->MacroArgsCache->empty());
-  ContentCache::MacroArgsMap::iterator
-      I = Content->MacroArgsCache->upper_bound(Offset);
+  assert(!MacroArgsCache->empty());
+  MacroArgsMap::iterator I = MacroArgsCache->upper_bound(Offset);
   --I;
   
   unsigned MacroArgBeginOffs = I->first;
@@ -1720,13 +1721,12 @@
                << "B of Sloc address space used.\n";
   
   unsigned NumLineNumsComputed = 0;
-  unsigned NumMacroArgsComputed = 0;
   unsigned NumFileBytesMapped = 0;
   for (fileinfo_iterator I = fileinfo_begin(), E = fileinfo_end(); I != E; ++I){
     NumLineNumsComputed += I->second->SourceLineCache != 0;
-    NumMacroArgsComputed += I->second->MacroArgsCache != 0;
     NumFileBytesMapped  += I->second->getSizeBytesMapped();
   }
+  unsigned NumMacroArgsComputed = MacroArgsCacheMap.size();
 
   llvm::errs() << NumFileBytesMapped << " bytes of files mapped, "
                << NumLineNumsComputed << " files with line #'s computed, "