[cfe-commits] r169960 - in /cfe/trunk: lib/Lex/Preprocessor.cpp test/Preprocessor/warn-disabled-macro-expansion.c

Richard Smith richard-llvm at metafoo.co.uk
Tue Dec 11 18:46:14 PST 2012


Author: rsmith
Date: Tue Dec 11 20:46:14 2012
New Revision: 169960

URL: http://llvm.org/viewvc/llvm-project?rev=169960&view=rev
Log:
Don't warn about disabled macro expansion if we see the name of a function-like macro which isn't immediately followed by '('. FreeBSD's stdio.h #defines foo(x) to (foo)(x), apparently.

Modified:
    cfe/trunk/lib/Lex/Preprocessor.cpp
    cfe/trunk/test/Preprocessor/warn-disabled-macro-expansion.c

Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=169960&r1=169959&r2=169960&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Tue Dec 11 20:46:14 2012
@@ -592,9 +592,7 @@
   // If this is a macro to be expanded, do it.
   if (MacroInfo *MI = getMacroInfo(&II)) {
     if (!DisableMacroExpansion) {
-      if (Identifier.isExpandDisabled()) {
-        Diag(Identifier, diag::pp_disabled_macro_expansion);
-      } else if (MI->isEnabled()) {
+      if (!Identifier.isExpandDisabled() && MI->isEnabled()) {
         if (!HandleMacroExpandedIdentifier(Identifier, MI))
           return;
       } else {
@@ -602,7 +600,8 @@
         // expanded, even if it's in a context where it could be expanded in the
         // future.
         Identifier.setFlag(Token::DisableExpand);
-        Diag(Identifier, diag::pp_disabled_macro_expansion);
+        if (MI->isObjectLike() || isNextPPTokenLParen())
+          Diag(Identifier, diag::pp_disabled_macro_expansion);
       }
     }
   }

Modified: cfe/trunk/test/Preprocessor/warn-disabled-macro-expansion.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/warn-disabled-macro-expansion.c?rev=169960&r1=169959&r2=169960&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/warn-disabled-macro-expansion.c (original)
+++ cfe/trunk/test/Preprocessor/warn-disabled-macro-expansion.c Tue Dec 11 20:46:14 2012
@@ -14,6 +14,8 @@
 
 #define c(x) x(0)
 
+#define z(x) (z)(x)
+
 p // expected-warning {{recursive macro}}
 
 a // expected-warning {{recursive macro}}
@@ -25,3 +27,5 @@
 h(0) // expected-warning {{recursive macro}}
 
 c(c) // expected-warning {{recursive macro}}
+
+z(z) // ok





More information about the cfe-commits mailing list