[llvm-commits] [TableGen] Invalid flat operand number

Bill Wendling wendling at apple.com
Wed Nov 7 11:05:08 PST 2012


On Nov 7, 2012, at 9:17 AM, Evandro Menezes <emenezes at codeaurora.org> wrote:

> I came across an issue in TableGen when working on adding opcodes to the Hexagon insn tables:
> 
> llvm-tblgen: utils/TableGen/CodeGenInstruction.h:180: std::pair<unsigned int, unsigned int> llvm::CGIOperandList::getSubOperandNumber(unsigned int) const: Assertion `i < OperandList.size() && "Invalid flat operand #"' failed.
> 
> The problem is that higher up a list of operands is iterated over without regard to the number of operands in it, which this patch tries to address.
> 
> Does it look good to you?
> 
Index: utils/TableGen/CodeEmitterGen.cpp
===================================================================
--- utils/TableGen/CodeEmitterGen.cpp	(revision 167485)
+++ utils/TableGen/CodeEmitterGen.cpp	(working copy)
@@ -136,8 +136,12 @@
   } else {
     /// If this operand is not supposed to be emitted by the
     /// generated emitter, skip it.
-    while (CGI.Operands.isFlatOperandNotEmitted(NumberedOp))
+    while (NumberedOp < CGI.Operands.size() &&
+           CGI.Operands.isFlatOperandNotEmitted(NumberedOp))
       ++NumberedOp;
+    // If this operand has not been found, ignore it.
+    if (NumberedOp >= CGI.Operands.size())
+      return;
     OpIdx = NumberedOp++;
   }
   

You shouldn't be recalculating the size of 'CGI.Operands' for each iteration of the loop. I'm also concerned about that value of NumberedOp once this returns. How does it being '>= CGI.Operands' affect the caller of this method?

-bw




More information about the llvm-commits mailing list