[cfe-commits] r90735 - in /cfe/trunk: lib/Frontend/PrintPreprocessedOutput.cpp test/Preprocessor/dump_macros.c
Chris Lattner
sabre at nondot.org
Sun Dec 6 17:58:34 PST 2009
Author: lattner
Date: Sun Dec 6 19:58:34 2009
New Revision: 90735
URL: http://llvm.org/viewvc/llvm-project?rev=90735&view=rev
Log:
fix -dM with variadic macros, PR5699
Modified:
cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
cfe/trunk/test/Preprocessor/dump_macros.c
Modified: cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp?rev=90735&r1=90734&r2=90735&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp (original)
+++ cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp Sun Dec 6 19:58:34 2009
@@ -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 @@
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 << ')';
}
Modified: cfe/trunk/test/Preprocessor/dump_macros.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/dump_macros.c?rev=90735&r1=90734&r2=90735&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/dump_macros.c (original)
+++ cfe/trunk/test/Preprocessor/dump_macros.c Sun Dec 6 19:58:34 2009
@@ -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__
More information about the cfe-commits
mailing list