From: Chris Lattner Date: Mon, 28 Dec 2009 06:17:16 +0000 (+0000) Subject: The PreExpArgTokens array is indexed with an argument #, X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f5809a7b76fd5a86ae737d9b525a1eddb9339ee7;p=clang The PreExpArgTokens array is indexed with an argument #, not a token number. Fix the reserve logic to get the right amount of space. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92202 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Lex/MacroArgs.cpp b/lib/Lex/MacroArgs.cpp index c2cf623317..4883898e3c 100644 --- a/lib/Lex/MacroArgs.cpp +++ b/lib/Lex/MacroArgs.cpp @@ -132,13 +132,14 @@ bool MacroArgs::ArgNeedsPreexpansion(const Token *ArgTok, /// getPreExpArgument - Return the pre-expanded form of the specified /// argument. const std::vector & -MacroArgs::getPreExpArgument(unsigned Arg, Preprocessor &PP) { - assert(Arg < NumUnexpArgTokens && "Invalid argument number!"); +MacroArgs::getPreExpArgument(unsigned Arg, const MacroInfo *MI, + Preprocessor &PP) { + assert(Arg < MI->getNumArgs() && "Invalid argument number!"); // If we have already computed this, return it. - if (PreExpArgTokens.empty()) - PreExpArgTokens.resize(NumUnexpArgTokens); - + if (PreExpArgTokens.size() < MI->getNumArgs()) + PreExpArgTokens.resize(MI->getNumArgs()); + std::vector &Result = PreExpArgTokens[Arg]; if (!Result.empty()) return Result; diff --git a/lib/Lex/MacroArgs.h b/lib/Lex/MacroArgs.h index fa040c7a4d..6ff4856b4e 100644 --- a/lib/Lex/MacroArgs.h +++ b/lib/Lex/MacroArgs.h @@ -82,7 +82,7 @@ public: /// getPreExpArgument - Return the pre-expanded form of the specified /// argument. const std::vector & - getPreExpArgument(unsigned Arg, Preprocessor &PP); + getPreExpArgument(unsigned Arg, const MacroInfo *MI, Preprocessor &PP); /// getStringifiedArgument - Compute, cache, and return the specified argument /// that has been 'stringified' as required by the # operator. diff --git a/lib/Lex/TokenLexer.cpp b/lib/Lex/TokenLexer.cpp index 1083f63127..5d95eb39c8 100644 --- a/lib/Lex/TokenLexer.cpp +++ b/lib/Lex/TokenLexer.cpp @@ -175,7 +175,7 @@ void TokenLexer::ExpandFunctionArguments() { // avoids some work in common cases. const Token *ArgTok = ActualArgs->getUnexpArgument(ArgNo); if (ActualArgs->ArgNeedsPreexpansion(ArgTok, PP)) - ResultArgToks = &ActualArgs->getPreExpArgument(ArgNo, PP)[0]; + ResultArgToks = &ActualArgs->getPreExpArgument(ArgNo, Macro, PP)[0]; else ResultArgToks = ArgTok; // Use non-preexpanded tokens.