When copying a partial diagnostic into a DependentDiagnostic, allocate
storage for that partial diagnostic via the ASTContext's
BumpPtrAllocator rather than using up slots in the ASTContext's
cache. Now that we do this, we don't have to worry about destroying
dependent diagnostics when destroying a DependentStoredDeclsMap.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99854 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp
index cb6b76c..c693e15 100644
--- a/lib/AST/DeclBase.cpp
+++ b/lib/AST/DeclBase.cpp
@@ -994,17 +994,6 @@
   }
 }
 
-DependentStoredDeclsMap::~DependentStoredDeclsMap() {
-  // Kill off the dependent diagnostics.  They don't need to be
-  // deleted, but they do need to be destructed.
-  DependentDiagnostic *CurD = FirstDiagnostic;
-  while (CurD) {
-    DependentDiagnostic *NextD = CurD->NextDiagnostic;
-    CurD->~DependentDiagnostic();
-    CurD = NextD;
-  }
-}
-
 DependentDiagnostic *DependentDiagnostic::Create(ASTContext &C,
                                                  DeclContext *Parent,
                                            const PartialDiagnostic &PDiag) {
@@ -1017,9 +1006,13 @@
   DependentStoredDeclsMap *Map
     = static_cast<DependentStoredDeclsMap*>(Parent->LookupPtr);
 
-  // FIXME: Allocate the copy of the PartialDiagnostic via the ASTContext's
+  // Allocate the copy of the PartialDiagnostic via the ASTContext's
   // BumpPtrAllocator, rather than the ASTContext itself.
-  DependentDiagnostic *DD = new (C) DependentDiagnostic(PDiag);
+  PartialDiagnostic::Storage *DiagStorage = 0;
+  if (PDiag.hasStorage())
+    DiagStorage = new (C) PartialDiagnostic::Storage;
+  
+  DependentDiagnostic *DD = new (C) DependentDiagnostic(PDiag, DiagStorage);
 
   // TODO: Maybe we shouldn't reverse the order during insertion.
   DD->NextDiagnostic = Map->FirstDiagnostic;