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

Chris Lattner sabre at nondot.org
Mon Apr 20 14:08:16 PDT 2009


Author: lattner
Date: Mon Apr 20 16:08:10 2009
New Revision: 69627

URL: http://llvm.org/viewvc/llvm-project?rev=69627&view=rev
Log:
fix the second half of PR4006 and rdar://6807000 by treating
() as being either zero arguments or one empty argument depending
on situation.

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

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

==============================================================================
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Mon Apr 20 16:08:10 2009
@@ -392,7 +392,16 @@
   
   if (NumActuals < MinArgsExpected) {
     // There are several cases where too few arguments is ok, handle them now.
-    if (NumActuals+1 == MinArgsExpected && MI->isVariadic()) {
+    if (NumActuals == 0 && MinArgsExpected == 1) {
+      // #define A(X)  or  #define A(...)   ---> A()
+      
+      // If there is exactly one argument, and that argument is missing,
+      // then we have an empty "()" argument empty list.  This is fine, even if
+      // the macro expects one argument (the argument is just empty).
+      isVarargsElided = MI->isVariadic();
+    } else if (MI->isVariadic() &&
+               (NumActuals+1 == MinArgsExpected ||  // A(x, ...) -> A(X)
+                (NumActuals == 0 && MinArgsExpected == 2))) {// A(x,...) -> A()
       // Varargs where the named vararg parameter is missing: ok as extension.
       // #define A(x, ...)
       // A("blah")
@@ -404,12 +413,7 @@
       //   #define B(x, ...) blah(a, ## __VA_ARGS__) 
       //   #define C(...) blah(a, ## __VA_ARGS__) 
       //  A(x) B(x) C()
-      isVarargsElided = true; //MI->getNumArgs() > 1;
-    } else if (NumActuals == 0 && MinArgsExpected == 1) {
-      assert(!MI->isVariadic() && "Variadic should be handled by case above");
-      // If there is exactly one argument, and that argument is missing,
-      // then we have an empty "()" argument empty list.  This is fine, even if
-      // the macro expects one argument (the argument is just empty).
+      isVarargsElided = true;
     } else {
       // Otherwise, emit the error.
       Diag(Tok, diag::err_too_few_args_in_macro_invoc);

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

==============================================================================
--- cfe/trunk/test/Preprocessor/macro_fn.c (original)
+++ cfe/trunk/test/Preprocessor/macro_fn.c Mon Apr 20 16:08:10 2009
@@ -4,6 +4,8 @@
 #define zero() 0
 #define one(x) 0
 #define two(x, y) 0
+#define zero_dot(...) 0   /* expected-warning {{variadic macros were introduced in C99}} */
+#define one_dot(x, ...) 0 /* expected-warning {{variadic macros were introduced in C99}} */
 
 zero()
 zero(1);          /* expected-error {{too many arguments provided to function-like macro invocation}} */
@@ -28,6 +30,11 @@
 
 
 
-/* PR4006 */
+/* PR4006 & rdar://6807000 */
 #define e(...) __VA_ARGS__  /* expected-warning {{variadic macros were introduced in C99}} */
 e(x)
+e()
+
+zero_dot()
+one_dot(x)  /* empty ... argument: expected-warning {{varargs argument missing, but tolerated as an extension}}  */
+one_dot()   /* empty first argument, elided ...: expected-warning {{varargs argument missing, but tolerated as an extension}} */





More information about the cfe-commits mailing list