diff options
author | Chris Lattner <sabre@nondot.org> | 2009-03-25 21:08:24 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-03-25 21:08:24 +0000 |
commit | 4fcb4cd6556cd783b2a8cd2b7266ae4696e605bb (patch) | |
tree | 62373260ee6e47a5cc7b89aa86de5c39c377c480 | |
parent | 03162d6d2aef5667816ce19788b6a752299bea43 (diff) |
fix PR3880, fixing a comma swallowing bug handling macros that only take
... arguments.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67706 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Lex/PPMacroExpansion.cpp | 6 | ||||
-rw-r--r-- | test/Preprocessor/macro_fn_comma_swallow.c | 5 |
2 files changed, 11 insertions, 0 deletions
diff --git a/lib/Lex/PPMacroExpansion.cpp b/lib/Lex/PPMacroExpansion.cpp index 6ec306196d..f1c69d9934 100644 --- a/lib/Lex/PPMacroExpansion.cpp +++ b/lib/Lex/PPMacroExpansion.cpp @@ -403,6 +403,12 @@ MacroArgs *Preprocessor::ReadFunctionLikeMacroArgs(Token &MacroName, Tok.setLocation(EndLoc); Tok.setLength(0); ArgTokens.push_back(Tok); + } else if (NumActuals == 1 && ArgTokens.size() == 1) { + // If there is exactly one argument, and that argument is just an EOF token, + // then we have an empty "()" argument empty list. This is fine, even if + // the macro expects one argument (the argument is just empty). However, if + // the macro expects "...", then we need to know that it was elided. + isVarargsElided = MinArgsExpected == 1 && MI->isVariadic(); } return MacroArgs::create(MI, &ArgTokens[0], ArgTokens.size(),isVarargsElided); diff --git a/test/Preprocessor/macro_fn_comma_swallow.c b/test/Preprocessor/macro_fn_comma_swallow.c index 4e06f89a16..e985138a5c 100644 --- a/test/Preprocessor/macro_fn_comma_swallow.c +++ b/test/Preprocessor/macro_fn_comma_swallow.c @@ -14,3 +14,8 @@ X2() X3(foo) + +// RUN: clang-cc %s -E | grep 'AA BB' +// PR3880 +#define X4(...) AA , ## __VA_ARGS__ BB +X4() |