From 9dfed9fdb64e8b9e81aba9c749059287a044e134 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 7 Dec 2009 01:58:34 +0000 Subject: [PATCH] fix -dM with variadic macros, PR5699 llvm-svn: 90735 --- .../lib/Frontend/PrintPreprocessedOutput.cpp | 23 ++++++++++++------- clang/test/Preprocessor/dump_macros.c | 9 ++++++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/clang/lib/Frontend/PrintPreprocessedOutput.cpp b/clang/lib/Frontend/PrintPreprocessedOutput.cpp index e0186abeb49c..c23c6e3b9a80 100644 --- a/clang/lib/Frontend/PrintPreprocessedOutput.cpp +++ b/clang/lib/Frontend/PrintPreprocessedOutput.cpp @@ -28,6 +28,13 @@ #include 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(); + while (AI != E) { + OS << ','; + PrintArgName(*AI++, OS); + } } - if (MI.isVariadic()) { - if (!MI.arg_empty()) - OS << ','; - OS << "..."; - } + if (MI.isGNUVarargs()) + OS << "..."; // #define foo(x...) + OS << ')'; } diff --git a/clang/test/Preprocessor/dump_macros.c b/clang/test/Preprocessor/dump_macros.c index 29b1d293943e..b4d290612722 100644 --- a/clang/test/Preprocessor/dump_macros.c +++ b/clang/test/Preprocessor/dump_macros.c @@ -27,3 +27,12 @@ #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__