summaryrefslogtreecommitdiffstats
path: root/clang/Lex/MacroExpander.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-07-29 04:04:22 +0000
committerChris Lattner <sabre@nondot.org>2006-07-29 04:04:22 +0000
commit21c8b8f71e1247c33ea8b9291f756b428de57651 (patch)
tree2462bc78d2ee04f6c6c2cb1f398f2c1c46439317 /clang/Lex/MacroExpander.cpp
parent2bc48570b714ae87e57f20440d27b4664e18d819 (diff)
downloadbcm5719-llvm-21c8b8f71e1247c33ea8b9291f756b428de57651.tar.gz
bcm5719-llvm-21c8b8f71e1247c33ea8b9291f756b428de57651.zip
Implement support for __VA_ARGS__, allowing test/Preprocessor/macro_fn_varargs_iso.c
to pass. llvm-svn: 38776
Diffstat (limited to 'clang/Lex/MacroExpander.cpp')
-rw-r--r--clang/Lex/MacroExpander.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/clang/Lex/MacroExpander.cpp b/clang/Lex/MacroExpander.cpp
index 27b4cc80555..e129ed69e97 100644
--- a/clang/Lex/MacroExpander.cpp
+++ b/clang/Lex/MacroExpander.cpp
@@ -246,7 +246,7 @@ MacroExpander::MacroExpander(LexerToken &Tok, MacroArgs *Actuals,
// If this is a function-like macro, expand the arguments and change
// MacroTokens to point to the expanded tokens.
- if (Macro->isFunctionLike() && Macro->getNumArgs())
+ if (Macro->isFunctionLike() && Macro->getNumArgs() || Macro->isC99Varargs())
ExpandFunctionArguments();
// Mark the macro as currently disabled, so that it is not recursively
@@ -288,6 +288,8 @@ MacroExpander::~MacroExpander() {
void MacroExpander::ExpandFunctionArguments() {
SmallVector<LexerToken, 128> ResultToks;
+ IdentifierInfo *VAARGSii = PP.get__VA_ARGS__Identifier();
+
// Loop through the MacroTokens tokens, expanding them into ResultToks. Keep
// track of whether we change anything. If not, no need to keep them. If so,
// we install the newly expanded sequence as MacroTokens.
@@ -325,8 +327,14 @@ void MacroExpander::ExpandFunctionArguments() {
IdentifierInfo *II = CurTok.getIdentifierInfo();
int ArgNo = II ? Macro->getArgumentNum(II) : -1;
if (ArgNo == -1) {
- ResultToks.push_back(CurTok);
- continue;
+ if (II != VAARGSii || !Macro->isC99Varargs()) {
+ // This isn't an argument and isn't __VA_ARGS__. Just add it.
+ ResultToks.push_back(CurTok);
+ continue;
+ }
+
+ // Otherwise, this *is* __VA_ARGS__. Set ArgNo to the last argument.
+ ArgNo = Macro->getNumArgs();
}
// An argument is expanded somehow, the result is different than the
OpenPOWER on IntegriCloud