]> granicus.if.org Git - clang/commitdiff
require the MAcroInfo objects are explcitly destroyed.
authorChris Lattner <sabre@nondot.org>
Fri, 20 Feb 2009 22:19:20 +0000 (22:19 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 20 Feb 2009 22:19:20 +0000 (22:19 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65179 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Lex/MacroInfo.h
include/clang/Lex/Preprocessor.h
lib/Lex/PPDirectives.cpp
lib/Lex/Preprocessor.cpp

index 7e0125f496d04dfad401c47393bde74741bfca89..a09c564fd9c68535f1d8d13ce9f9962d0f2b1bf9 100644 (file)
@@ -76,7 +76,12 @@ public:
   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.
index 1608466fe2ef6edce11e02691efc7212d23840dd..a0ed1767df34f12376a9477e031ddd7a09326e95 100644 (file)
@@ -579,9 +579,7 @@ private:
   
   /// 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.
index c38310b925f93502c3f2c99682dba78c320ea139..5a100995b8a685d200fcd68ab04022c6bd227c0e 100644 (file)
@@ -24,18 +24,26 @@ using namespace clang;
 // Utility Methods for Preprocessor Directive Handling.
 //===----------------------------------------------------------------------===//
 
-MacroInfoPreprocessor::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() {
index 31a040674f7efed4509036ce75ee34d5eb90de5d..7b34cb65e368464758c23cc51b803a5cf4871edf 100644 (file)
@@ -101,6 +101,7 @@ Preprocessor::~Preprocessor() {
     // 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);
   }