diff options
author | Chris Lattner <sabre@nondot.org> | 2010-08-21 00:27:00 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-08-21 00:27:00 +0000 |
commit | 20a2b46ca20070b0ddf3040ba8e3e7da301cca5f (patch) | |
tree | 9accd4ecf7b4b4b33bbe167f38cfdc34518d05a9 | |
parent | 7a3f3a0402a86dca9fa528e806a725a0b2841d1c (diff) | |
download | bcm5719-llvm-20a2b46ca20070b0ddf3040ba8e3e7da301cca5f.tar.gz bcm5719-llvm-20a2b46ca20070b0ddf3040ba8e3e7da301cca5f.zip |
fix PR7943, a corner case with the GNU __VA_ARGS__ comma
swallowing extension.
llvm-svn: 111701
-rw-r--r-- | clang/lib/Lex/TokenLexer.cpp | 7 | ||||
-rw-r--r-- | clang/test/Preprocessor/macro_fn_comma_swallow.c | 5 |
2 files changed, 12 insertions, 0 deletions
diff --git a/clang/lib/Lex/TokenLexer.cpp b/clang/lib/Lex/TokenLexer.cpp index 49dc016590a..94719b0baa3 100644 --- a/clang/lib/Lex/TokenLexer.cpp +++ b/clang/lib/Lex/TokenLexer.cpp @@ -268,6 +268,13 @@ void TokenLexer::ExpandFunctionArguments() { // Remove the paste operator, report use of the extension. PP.Diag(ResultToks.back().getLocation(), diag::ext_paste_comma); ResultToks.pop_back(); + + // If the comma was right after another paste (e.g. "X##,##__VA_ARGS__"), + // then removal of the comma should produce a placemarker token (in C99 + // terms) which we model by popping off the previous ##, giving us a plain + // "X" when __VA_ARGS__ is empty. + if (!ResultToks.empty() && ResultToks.back().is(tok::hashhash)) + ResultToks.pop_back(); } continue; } diff --git a/clang/test/Preprocessor/macro_fn_comma_swallow.c b/clang/test/Preprocessor/macro_fn_comma_swallow.c index 57425910b8a..fd32c84765f 100644 --- a/clang/test/Preprocessor/macro_fn_comma_swallow.c +++ b/clang/test/Preprocessor/macro_fn_comma_swallow.c @@ -19,3 +19,8 @@ X3(foo) // PR3880 #define X4(...) AA , ## __VA_ARGS__ BB X4() + +// RUN: %clang_cc1 %s -E | grep '5: 1' +// PR7943 +#define X5(x,...) x##,##__VA_ARGS__ +5: X5(1) |