[cfe-commits] r50843 - in /cfe/trunk: lib/Lex/PPMacroExpansion.cpp test/Preprocessor/macro_fn_varargs_named.c

Chris Lattner sabre at nondot.org
Wed May 7 22:10:33 PDT 2008


Author: lattner
Date: Thu May  8 00:10:33 2008
New Revision: 50843

URL: http://llvm.org/viewvc/llvm-project?rev=50843&view=rev
Log:
The awesome GNU "comma elision extension" works with both the standard
__VA_ARGS__ syntax as well as with the amazingly awesome GNU "named 
variadic macro" extension.  Allow it with the GNU syntax as well.

Modified:
    cfe/trunk/lib/Lex/PPMacroExpansion.cpp
    cfe/trunk/test/Preprocessor/macro_fn_varargs_named.c

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

==============================================================================
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Thu May  8 00:10:33 2008
@@ -370,9 +370,12 @@
       // A("blah")
       Diag(Tok, diag::ext_missing_varargs_arg);
 
-      // Remember this occurred if this is a C99 macro invocation with at least
-      // one actual argument.
-      isVarargsElided = MI->isC99Varargs() && MI->getNumArgs() > 1;
+      // Remember this occurred if this is a macro invocation with at least
+      // one actual argument.  This allows us to elide the comma when used for
+      // cases like:
+      //   #define A(x, foo...) blah(a, ## foo) 
+      //   #define A(x, ...) blah(a, ## __VA_ARGS__) 
+      isVarargsElided = MI->getNumArgs() > 1;
     } else if (MI->getNumArgs() == 1) {
       // #define A(x)
       //   A()

Modified: cfe/trunk/test/Preprocessor/macro_fn_varargs_named.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/macro_fn_varargs_named.c?rev=50843&r1=50842&r2=50843&view=diff

==============================================================================
--- cfe/trunk/test/Preprocessor/macro_fn_varargs_named.c (original)
+++ cfe/trunk/test/Preprocessor/macro_fn_varargs_named.c Thu May  8 00:10:33 2008
@@ -1,7 +1,10 @@
 // RUN: clang -E %s | grep '^a: x$' &&
 // RUN: clang -E %s | grep '^b: x y, z,h$'
+// RUN: clang -E %s | grep '^c: foo(x)$'
 
 #define A(b, c...) b c
 a: A(x)
 b: A(x, y, z,h)
 
+#define B(b, c...) foo(b, ## c)
+c: B(x)





More information about the cfe-commits mailing list