Browse Source

[NFC] Add assertion that we assume a valid macro argument index.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@314600 91177308-0d34-0410-b5e6-96231b3b80d8
Faisal Vali 8 years ago
parent
commit
744bd75982
1 changed files with 3 additions and 0 deletions
  1. 3 0
      lib/Lex/MacroArgs.cpp

+ 3 - 0
lib/Lex/MacroArgs.cpp

@@ -118,10 +118,13 @@ unsigned MacroArgs::getArgLength(const Token *ArgPtr) {
 /// getUnexpArgument - Return the unexpanded tokens for the specified formal.
 /// getUnexpArgument - Return the unexpanded tokens for the specified formal.
 ///
 ///
 const Token *MacroArgs::getUnexpArgument(unsigned Arg) const {
 const Token *MacroArgs::getUnexpArgument(unsigned Arg) const {
+
+  assert(Arg < getNumMacroArguments() && "Invalid arg #");
   // The unexpanded argument tokens start immediately after the MacroArgs object
   // The unexpanded argument tokens start immediately after the MacroArgs object
   // in memory.
   // in memory.
   const Token *Start = getTrailingObjects<Token>();
   const Token *Start = getTrailingObjects<Token>();
   const Token *Result = Start;
   const Token *Result = Start;
+  
   // Scan to find Arg.
   // Scan to find Arg.
   for (; Arg; ++Result) {
   for (; Arg; ++Result) {
     assert(Result < Start+NumUnexpArgTokens && "Invalid arg #");
     assert(Result < Start+NumUnexpArgTokens && "Invalid arg #");