[cfe-commits] r172623 - in /cfe/trunk/lib/Lex: PPDirectives.cpp PreprocessingRecord.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Wed Jan 16 08:52:44 PST 2013


Author: akirtzidis
Date: Wed Jan 16 10:52:44 2013
New Revision: 172623

URL: http://llvm.org/viewvc/llvm-project?rev=172623&view=rev
Log:
[preprocessor] Call the MacroUndefined callback even when the macro was not defined.

Patch by Enea Zaffanella!

Modified:
    cfe/trunk/lib/Lex/PPDirectives.cpp
    cfe/trunk/lib/Lex/PreprocessingRecord.cpp

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=172623&r1=172622&r2=172623&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Wed Jan 16 10:52:44 2013
@@ -1967,16 +1967,17 @@
   // Okay, we finally have a valid identifier to undef.
   MacroInfo *MI = getMacroInfo(MacroNameTok.getIdentifierInfo());
 
+  // If the callbacks want to know, tell them about the macro #undef.
+  // Note: no matter if the macro was defined or not.
+  if (Callbacks)
+    Callbacks->MacroUndefined(MacroNameTok, MI);
+
   // If the macro is not defined, this is a noop undef, just return.
   if (MI == 0) return;
 
   if (!MI->isUsed() && MI->isWarnIfUnused())
     Diag(MI->getDefinitionLoc(), diag::pp_macro_not_used);
 
-  // If the callbacks want to know, tell them about the macro #undef.
-  if (Callbacks)
-    Callbacks->MacroUndefined(MacroNameTok, MI);
-
   if (MI->isWarnIfUnused())
     WarnUnusedMacroLocs.erase(MI->getDefinitionLoc());
 

Modified: cfe/trunk/lib/Lex/PreprocessingRecord.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PreprocessingRecord.cpp?rev=172623&r1=172622&r2=172623&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PreprocessingRecord.cpp (original)
+++ cfe/trunk/lib/Lex/PreprocessingRecord.cpp Wed Jan 16 10:52:44 2013
@@ -416,7 +416,9 @@
 
 void PreprocessingRecord::MacroUndefined(const Token &Id,
                                          const MacroInfo *MI) {
-  MacroDefinitions.erase(MI);
+  // Note: MI may be null (when #undef'ining an undefined macro).
+  if (MI)
+    MacroDefinitions.erase(MI);
 }
 
 void PreprocessingRecord::InclusionDirective(





More information about the cfe-commits mailing list