require the MAcroInfo objects are explcitly destroyed.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65179 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Lex/MacroInfo.h b/include/clang/Lex/MacroInfo.h
index 7e0125f..a09c564 100644
--- a/include/clang/Lex/MacroInfo.h
+++ b/include/clang/Lex/MacroInfo.h
@@ -76,7 +76,12 @@
   MacroInfo(SourceLocation DefLoc);
   
   ~MacroInfo() {
+    assert(ArgumentList == 0 && "Didn't call destroy before dtor!");
+  }
+  
+  void Destroy() {
     delete[] ArgumentList;
+    ArgumentList = 0;
   }
   
   /// getDefinitionLoc - Return the location that the macro was defined at.
diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h
index 1608466..a0ed176 100644
--- a/include/clang/Lex/Preprocessor.h
+++ b/include/clang/Lex/Preprocessor.h
@@ -579,9 +579,7 @@
   
   /// ReleaseMacroInfo - Release the specified MacroInfo.  This memory will
   ///  be reused for allocating new MacroInfo objects.
-  void ReleaseMacroInfo(MacroInfo* MI) {
-    MICache.push_back(MI);
-  }
+  void ReleaseMacroInfo(MacroInfo* MI);
   
   /// isInPrimaryFile - Return true if we're in the top-level file, not in a
   /// #include.
diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp
index c38310b..5a10099 100644
--- a/lib/Lex/PPDirectives.cpp
+++ b/lib/Lex/PPDirectives.cpp
@@ -24,18 +24,26 @@
 // Utility Methods for Preprocessor Directive Handling.
 //===----------------------------------------------------------------------===//
 
-MacroInfo* Preprocessor::AllocateMacroInfo(SourceLocation L) {
+MacroInfo *Preprocessor::AllocateMacroInfo(SourceLocation L) {
   MacroInfo *MI;
   
   if (!MICache.empty()) {
     MI = MICache.back();
     MICache.pop_back();
-  }
-  else MI = (MacroInfo*) BP.Allocate<MacroInfo>();
+  } else
+    MI = (MacroInfo*) BP.Allocate<MacroInfo>();
   new (MI) MacroInfo(L);
   return MI;
 }
 
+/// ReleaseMacroInfo - Release the specified MacroInfo.  This memory will
+///  be reused for allocating new MacroInfo objects.
+void Preprocessor::ReleaseMacroInfo(MacroInfo* MI) {
+  MICache.push_back(MI);
+  MI->Destroy();
+}
+
+
 /// DiscardUntilEndOfDirective - Read and discard all tokens remaining on the
 /// current line until the tok::eom token is found.
 void Preprocessor::DiscardUntilEndOfDirective() {
diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp
index 31a0406..7b34cb6 100644
--- a/lib/Lex/Preprocessor.cpp
+++ b/lib/Lex/Preprocessor.cpp
@@ -101,6 +101,7 @@
     // will be released when the BumpPtrAllocator 'BP' object gets
     // destroyed. We still need to run the dstor, however, to free
     // memory alocated by MacroInfo.
+    I->second->Destroy();
     I->second->~MacroInfo();    
     I->first->setHasMacroDefinition(false);
   }