Skip to content

Commit b11b440

Browse files
committed
[IR] Add bounds checking to paramHasAttr
Summary: This is intended to make a later change simpler. Note: adding this bounds checking required fixing `X86FastISel`. As far I can tell I've preserved original behavior but a careful review will be appreciated. Reviewers: reames Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D14304 llvm-svn: 252073
1 parent 2c38141 commit b11b440

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

llvm/lib/IR/Instructions.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,8 @@ void CallInst::addDereferenceableOrNullAttr(unsigned i, uint64_t Bytes) {
331331
}
332332

333333
bool CallInst::paramHasAttr(unsigned i, Attribute::AttrKind A) const {
334+
assert(i < (getNumArgOperands() + 1) && "Param index out of bounds!");
335+
334336
if (AttributeList.hasAttribute(i, A))
335337
return true;
336338
if (const Function *F = getCalledFunction())
@@ -575,6 +577,8 @@ bool InvokeInst::hasFnAttrImpl(Attribute::AttrKind A) const {
575577
}
576578

577579
bool InvokeInst::paramHasAttr(unsigned i, Attribute::AttrKind A) const {
580+
assert(i < (getNumArgOperands() + 1) && "Param index out of bounds!");
581+
578582
if (AttributeList.hasAttribute(i, A))
579583
return true;
580584
if (const Function *F = getCalledFunction())

llvm/lib/Target/X86/X86FastISel.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2817,10 +2817,12 @@ static unsigned computeBytesPoppedByCallee(const X86Subtarget *Subtarget,
28172817
if (CC == CallingConv::Fast || CC == CallingConv::GHC ||
28182818
CC == CallingConv::HiPE)
28192819
return 0;
2820-
if (CS && !CS->paramHasAttr(1, Attribute::StructRet))
2821-
return 0;
2822-
if (CS && CS->paramHasAttr(1, Attribute::InReg))
2823-
return 0;
2820+
2821+
if (CS)
2822+
if (CS->arg_empty() || !CS->paramHasAttr(1, Attribute::StructRet) ||
2823+
CS->paramHasAttr(1, Attribute::InReg))
2824+
return 0;
2825+
28242826
return 4;
28252827
}
28262828

0 commit comments

Comments
 (0)