fix -dM with variadic macros, PR5699

llvm-svn: 90735
This commit is contained in:
Chris Lattner 2009-12-07 01:58:34 +00:00
parent 5a6fb511c7
commit 9dfed9fdb6
2 changed files with 24 additions and 8 deletions

View File

@ -28,6 +28,13 @@
#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();
while (AI != E) {
OS << ',';
PrintArgName(*AI++, OS);
}
}
if (MI.isVariadic()) {
if (!MI.arg_empty())
OS << ',';
OS << "...";
}
if (MI.isGNUVarargs())
OS << "..."; // #define foo(x...)
OS << ')';
}

View File

@ -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__