r214675 - Don't destroy MacroInfos if we find the macro definition is invalid; it'll get

Richard Smith richard-llvm at metafoo.co.uk
Sun Aug 3 16:41:04 PDT 2014


Author: rsmith
Date: Sun Aug  3 18:41:04 2014
New Revision: 214675

URL: http://llvm.org/viewvc/llvm-project?rev=214675&view=rev
Log:
Don't destroy MacroInfos if we find the macro definition is invalid; it'll get
destroyed on shutdown regardless. Fixes a double-delete.

Modified:
    cfe/trunk/include/clang/Lex/Preprocessor.h
    cfe/trunk/lib/Lex/PPDirectives.cpp
    cfe/trunk/test/Lexer/string-literal-errors.cpp

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=214675&r1=214674&r2=214675&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Sun Aug  3 18:41:04 2014
@@ -1378,11 +1378,6 @@ private:
   VisibilityMacroDirective *AllocateVisibilityMacroDirective(SourceLocation Loc,
                                                              bool isPublic);
 
-  /// \brief Release the specified MacroInfo for re-use.
-  ///
-  /// This memory will  be reused for allocating new MacroInfo objects.
-  void ReleaseMacroInfo(MacroInfo* MI);
-
   /// \brief Lex and validate a macro name, which occurs after a
   /// \#define or \#undef. 
   ///

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=214675&r1=214674&r2=214675&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Sun Aug  3 18:41:04 2014
@@ -90,13 +90,6 @@ Preprocessor::AllocateVisibilityMacroDir
   return new (BP) VisibilityMacroDirective(Loc, isPublic);
 }
 
-/// \brief Clean up a MacroInfo that was allocated but not used due to an
-/// error in the macro definition.
-void Preprocessor::ReleaseMacroInfo(MacroInfo *MI) {
-  // Don't try to reuse the storage; this only happens on error paths.
-  MI->~MacroInfo();
-}
-
 /// \brief Read and discard all tokens remaining on the current line until
 /// the tok::eod token is found.
 void Preprocessor::DiscardUntilEndOfDirective() {
@@ -1902,8 +1895,6 @@ void Preprocessor::HandleDefineDirective
     // This is a function-like macro definition.  Read the argument list.
     MI->setIsFunctionLike();
     if (ReadMacroDefinitionArgList(MI, LastTok)) {
-      // Forget about MI.
-      ReleaseMacroInfo(MI);
       // Throw away the rest of the line.
       if (CurPPLexer->ParsingPreprocessorDirective)
         DiscardUntilEndOfDirective();
@@ -2028,7 +2019,6 @@ void Preprocessor::HandleDefineDirective
           continue;
         } else {
           Diag(Tok, diag::err_pp_stringize_not_parameter);
-          ReleaseMacroInfo(MI);
 
           // Disable __VA_ARGS__ again.
           Ident__VA_ARGS__->setIsPoisoned(true);
@@ -2056,12 +2046,10 @@ void Preprocessor::HandleDefineDirective
   if (NumTokens != 0) {
     if (MI->getReplacementToken(0).is(tok::hashhash)) {
       Diag(MI->getReplacementToken(0), diag::err_paste_at_start);
-      ReleaseMacroInfo(MI);
       return;
     }
     if (MI->getReplacementToken(NumTokens-1).is(tok::hashhash)) {
       Diag(MI->getReplacementToken(NumTokens-1), diag::err_paste_at_end);
-      ReleaseMacroInfo(MI);
       return;
     }
   }

Modified: cfe/trunk/test/Lexer/string-literal-errors.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/string-literal-errors.cpp?rev=214675&r1=214674&r2=214675&view=diff
==============================================================================
--- cfe/trunk/test/Lexer/string-literal-errors.cpp (original)
+++ cfe/trunk/test/Lexer/string-literal-errors.cpp Sun Aug  3 18:41:04 2014
@@ -23,3 +23,5 @@ void foo() {
   // CHECK: {{^       \^~$}}
   // CHECK: {{^          \^~$}}
 }
+
+#define foo() lots and lots of tokens, need at least 8 to fill up the smallvector buffer #BadThingsHappenNow





More information about the cfe-commits mailing list