[cfe-commits] r65179 - in /cfe/trunk: include/clang/Lex/MacroInfo.h include/clang/Lex/Preprocessor.h lib/Lex/PPDirectives.cpp lib/Lex/Preprocessor.cpp

Chris Lattner sabre at nondot.org
Fri Feb 20 14:19:20 PST 2009


Author: lattner
Date: Fri Feb 20 16:19:20 2009
New Revision: 65179

URL: http://llvm.org/viewvc/llvm-project?rev=65179&view=rev
Log:
require the MAcroInfo objects are explcitly destroyed.

Modified:
    cfe/trunk/include/clang/Lex/MacroInfo.h
    cfe/trunk/include/clang/Lex/Preprocessor.h
    cfe/trunk/lib/Lex/PPDirectives.cpp
    cfe/trunk/lib/Lex/Preprocessor.cpp

Modified: cfe/trunk/include/clang/Lex/MacroInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/MacroInfo.h?rev=65179&r1=65178&r2=65179&view=diff

==============================================================================
--- cfe/trunk/include/clang/Lex/MacroInfo.h (original)
+++ cfe/trunk/include/clang/Lex/MacroInfo.h Fri Feb 20 16:19:20 2009
@@ -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.

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=65179&r1=65178&r2=65179&view=diff

==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Fri Feb 20 16:19:20 2009
@@ -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.

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=65179&r1=65178&r2=65179&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Fri Feb 20 16:19:20 2009
@@ -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() {

Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=65179&r1=65178&r2=65179&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Fri Feb 20 16:19:20 2009
@@ -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);
   }





More information about the cfe-commits mailing list