]> granicus.if.org Git - clang/commitdiff
fix -dM with variadic macros, PR5699
authorChris Lattner <sabre@nondot.org>
Mon, 7 Dec 2009 01:58:34 +0000 (01:58 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 7 Dec 2009 01:58:34 +0000 (01:58 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90735 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Frontend/PrintPreprocessedOutput.cpp
test/Preprocessor/dump_macros.c

index e0186abeb49cbcdf5e74bbf1220b690df42bac99..c23c6e3b9a803e734cf324e198a6c801b5b0da75 100644 (file)
 #include <cstdio>
 using namespace clang;
 
+static void PrintArgName(const IdentifierInfo *II, llvm::raw_ostream &OS) {
+  if (II->getName() == "__VA_ARGS__")
+    OS << "...";
+  else
+    OS << II->getName();
+}
+
 /// PrintMacroDefinition - Print a macro definition in a form that will be
 /// properly accepted back as a definition.
 static void PrintMacroDefinition(const IdentifierInfo &II, const MacroInfo &MI,
@@ -39,19 +46,19 @@ static void PrintMacroDefinition(const IdentifierInfo &II, const MacroInfo &MI,
     if (MI.arg_empty())
       ;
     else if (MI.getNumArgs() == 1)
-      OS << (*MI.arg_begin())->getName();
+      PrintArgName(*MI.arg_begin(), OS);
     else {
       MacroInfo::arg_iterator AI = MI.arg_begin(), E = MI.arg_end();
       OS << (*AI++)->getName();
-      while (AI != E)
-        OS << ',' << (*AI++)->getName();
-    }
-
-    if (MI.isVariadic()) {
-      if (!MI.arg_empty())
+      while (AI != E) {
         OS << ',';
-      OS << "...";
+        PrintArgName(*AI++, OS);
+      }
     }
+
+    if (MI.isGNUVarargs())
+      OS << "...";  // #define foo(x...)
+    
     OS << ')';
   }
 
index 29b1d293943e67329ed455ae8afbd630e92873a1..b4d290612722d46504344d5b4dae36c4c244696b 100644 (file)
 #define G 1
 #undef G
 #define G 2
+
+// Variadic macros of various sorts. PR5699
+
+// CHECK: H(x,...) __VA_ARGS__
+#define H(x, ...) __VA_ARGS__
+// CHECK: I(...) __VA_ARGS__
+#define I(...) __VA_ARGS__
+// CHECK: J(x...) __VA_ARGS__
+#define J(x ...) __VA_ARGS__