From e9b0bdf80467029e99e94065463020df1f037202 Mon Sep 17 00:00:00 2001 From: Nuno Lopes Date: Fri, 25 May 2012 21:15:17 +0000 Subject: bounds checking: add support for byval arguments llvm-svn: 157498 --- llvm/lib/Transforms/Scalar/BoundsChecking.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'llvm/lib/Transforms/Scalar') diff --git a/llvm/lib/Transforms/Scalar/BoundsChecking.cpp b/llvm/lib/Transforms/Scalar/BoundsChecking.cpp index 4c3dea2317a..7b1a4170408 100644 --- a/llvm/lib/Transforms/Scalar/BoundsChecking.cpp +++ b/llvm/lib/Transforms/Scalar/BoundsChecking.cpp @@ -104,7 +104,6 @@ void BoundsChecking::emitBranchToTrap(Value *Cmp) { BasicBlock *Cont = OldBB->splitBasicBlock(Inst); OldBB->getTerminator()->eraseFromParent(); - // FIXME: add unlikely branch taken metadata? if (Cmp) BranchInst::Create(getTrapBB(), Cont, Cmp, OldBB); else @@ -152,6 +151,15 @@ ConstTriState BoundsChecking::computeAllocSize(Value *Alloc, uint64_t &Size, SizeValue = Builder->CreateMul(SizeValue, ArraySize); return NotConst; + // function arguments + } else if (Argument *A = dyn_cast(Alloc)) { + if (!A->hasByValAttr()) + return Dunno; + + PointerType *PT = cast(A->getType()); + Size = TD->getTypeAllocSize(PT->getElementType()); + return Const; + // ptr = select(ptr1, ptr2) } else if (SelectInst *SI = dyn_cast(Alloc)) { uint64_t SizeFalse; -- cgit v1.2.3