[IR] Add bounds checking to dataOperandHasImpliedAttr
authorSanjoy Das <sanjoy@playingwithpointers.com>
Thu, 5 Nov 2015 01:53:26 +0000 (01:53 +0000)
committerSanjoy Das <sanjoy@playingwithpointers.com>
Thu, 5 Nov 2015 01:53:26 +0000 (01:53 +0000)
This is similar to the bounds check added to paramHasAttr in r252073.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252130 91177308-0d34-0410-b5e6-96231b3b80d8

lib/IR/Instructions.cpp

index 7c3695b15310be8649f85fc9a39e130827c292a0..dfd711f5c23aa42d4c90443b6de64d64e900df5b 100644 (file)
@@ -343,6 +343,10 @@ bool CallInst::paramHasAttr(unsigned i, Attribute::AttrKind A) const {
 bool CallInst::dataOperandHasImpliedAttr(unsigned i,
                                          Attribute::AttrKind A) const {
 
+  // There are getNumOperands() - 1 data operands.  The last operand is the
+  // callee.
+  assert(i < getNumOperands() && "Data operand index out of bounds!");
+
   // The attribute A can either be directly specified, if the operand in
   // question is a call argument; or be indirectly implied by the kind of its
   // containing operand bundle, if the operand is a bundle operand.
@@ -603,6 +607,10 @@ bool InvokeInst::paramHasAttr(unsigned i, Attribute::AttrKind A) const {
 
 bool InvokeInst::dataOperandHasImpliedAttr(unsigned i,
                                            Attribute::AttrKind A) const {
+  // There are getNumOperands() - 3 data operands.  The last three operands are
+  // the callee and the two successor basic blocks.
+  assert(i < (getNumOperands() - 2) && "Data operand index out of bounds!");
+
   // The attribute A can either be directly specified, if the operand in
   // question is an invoke argument; or be indirectly implied by the kind of its
   // containing operand bundle, if the operand is a bundle operand.