diff options
author | Sanjoy Das <sanjoy@playingwithpointers.com> | 2015-11-04 20:33:45 +0000 |
---|---|---|
committer | Sanjoy Das <sanjoy@playingwithpointers.com> | 2015-11-04 20:33:45 +0000 |
commit | b11b440f8e354b858579af454e72988a3e5d768d (patch) | |
tree | 2d4344db0b056c81c5bdf246abd3160281f7b2e1 | |
parent | 2c38141423f6ed6ec4db641be76f61631366cbb1 (diff) | |
download | bcm5719-llvm-b11b440f8e354b858579af454e72988a3e5d768d.tar.gz bcm5719-llvm-b11b440f8e354b858579af454e72988a3e5d768d.zip |
[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
-rw-r--r-- | llvm/lib/IR/Instructions.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/Target/X86/X86FastISel.cpp | 10 |
2 files changed, 10 insertions, 4 deletions
diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp index 59ac99b6666..3394355cfb4 100644 --- a/llvm/lib/IR/Instructions.cpp +++ b/llvm/lib/IR/Instructions.cpp @@ -331,6 +331,8 @@ void CallInst::addDereferenceableOrNullAttr(unsigned i, uint64_t Bytes) { } bool CallInst::paramHasAttr(unsigned i, Attribute::AttrKind A) const { + assert(i < (getNumArgOperands() + 1) && "Param index out of bounds!"); + if (AttributeList.hasAttribute(i, A)) return true; if (const Function *F = getCalledFunction()) @@ -575,6 +577,8 @@ bool InvokeInst::hasFnAttrImpl(Attribute::AttrKind A) const { } bool InvokeInst::paramHasAttr(unsigned i, Attribute::AttrKind A) const { + assert(i < (getNumArgOperands() + 1) && "Param index out of bounds!"); + if (AttributeList.hasAttribute(i, A)) return true; if (const Function *F = getCalledFunction()) diff --git a/llvm/lib/Target/X86/X86FastISel.cpp b/llvm/lib/Target/X86/X86FastISel.cpp index 2cda8211ba9..914fd04ad6b 100644 --- a/llvm/lib/Target/X86/X86FastISel.cpp +++ b/llvm/lib/Target/X86/X86FastISel.cpp @@ -2817,10 +2817,12 @@ static unsigned computeBytesPoppedByCallee(const X86Subtarget *Subtarget, if (CC == CallingConv::Fast || CC == CallingConv::GHC || CC == CallingConv::HiPE) return 0; - if (CS && !CS->paramHasAttr(1, Attribute::StructRet)) - return 0; - if (CS && CS->paramHasAttr(1, Attribute::InReg)) - return 0; + + if (CS) + if (CS->arg_empty() || !CS->paramHasAttr(1, Attribute::StructRet) || + CS->paramHasAttr(1, Attribute::InReg)) + return 0; + return 4; } |