From f1bb42152a0375f2889bd7329eada2b6422c837e Mon Sep 17 00:00:00 2001 From: Evandro Menezes Date: Fri, 9 Nov 2012 20:29:37 +0000 Subject: [PATCH] Fix issue with invalid flat operand number Avoid iterating over list of operands beyond the number of operands in it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@167634 91177308-0d34-0410-b5e6-96231b3b80d8 --- utils/TableGen/CodeEmitterGen.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/utils/TableGen/CodeEmitterGen.cpp b/utils/TableGen/CodeEmitterGen.cpp index e60aec9568f..bcca15cd57e 100644 --- a/utils/TableGen/CodeEmitterGen.cpp +++ b/utils/TableGen/CodeEmitterGen.cpp @@ -134,10 +134,15 @@ AddCodeToMergeInOperand(Record *R, BitsInit *BI, const std::string &VarName, assert(!CGI.Operands.isFlatOperandNotEmitted(OpIdx) && "Explicitly used operand also marked as not emitted!"); } else { + unsigned NumberOps = CGI.Operands.size(); /// If this operand is not supposed to be emitted by the /// generated emitter, skip it. - while (CGI.Operands.isFlatOperandNotEmitted(NumberedOp)) + while (NumberedOp < NumberOps && + CGI.Operands.isFlatOperandNotEmitted(NumberedOp)) ++NumberedOp; + // If this operand has not been found, ignore it. + if (NumberedOp >= NumberOps) + return; OpIdx = NumberedOp++; }