]> granicus.if.org Git - clang/commitdiff
Only call the MacroExpands callback when we're actually going to
authorDouglas Gregor <dgregor@apple.com>
Thu, 28 Apr 2011 16:36:13 +0000 (16:36 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 28 Apr 2011 16:36:13 +0000 (16:36 +0000)
expand the macro, based on a patch by Ori Avtalion. Fixes PR9799.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130402 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/PPMacroExpansion.cpp

index 32b2188af58cde5e6c6533234b229806847f112d..bacd62464a311e15cf80aa9093e3e7e8b3ba36eb 100644 (file)
@@ -176,8 +176,6 @@ bool Preprocessor::isNextPPTokenLParen() {
 /// expanded as a macro, handle it and return the next token as 'Identifier'.
 bool Preprocessor::HandleMacroExpandedIdentifier(Token &Identifier,
                                                  MacroInfo *MI) {
-  if (Callbacks) Callbacks->MacroExpands(Identifier, MI);
-
   // If this is a macro expansion in the "#if !defined(x)" line for the file,
   // then the macro could expand to different things in other contexts, we need
   // to disable the optimization in this case.
@@ -185,6 +183,7 @@ bool Preprocessor::HandleMacroExpandedIdentifier(Token &Identifier,
 
   // If this is a builtin macro, like __LINE__ or _Pragma, handle it specially.
   if (MI->isBuiltinMacro()) {
+    if (Callbacks) Callbacks->MacroExpands(Identifier, MI);
     ExpandBuiltinMacro(Identifier);
     return false;
   }
@@ -225,6 +224,8 @@ bool Preprocessor::HandleMacroExpandedIdentifier(Token &Identifier,
   // Notice that this macro has been used.
   markMacroAsUsed(MI);
 
+  if (Callbacks) Callbacks->MacroExpands(Identifier, MI);
+  
   // If we started lexing a macro, enter the macro expansion body.
 
   // Remember where the token is instantiated.