aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNuno Lopes <nunoplopes@sapo.pt>2012-05-25 21:15:17 +0000
committerNuno Lopes <nunoplopes@sapo.pt>2012-05-25 21:15:17 +0000
commitd72d67da07299d7773bfd97f75a469accfdc58de (patch)
tree1c3a18e48cb45b88fc9df023aef94ea9e70a5b3e
parent06a2f42d11512ff0bbcb5b5f3299988bbc3bbec6 (diff)
bounds checking: add support for byval arguments
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@157498 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/Scalar/BoundsChecking.cpp10
-rw-r--r--test/Transforms/BoundsChecking/simple.ll9
2 files changed, 18 insertions, 1 deletions
diff --git a/lib/Transforms/Scalar/BoundsChecking.cpp b/lib/Transforms/Scalar/BoundsChecking.cpp
index 4c3dea2317..7b1a417040 100644
--- a/lib/Transforms/Scalar/BoundsChecking.cpp
+++ b/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<Argument>(Alloc)) {
+ if (!A->hasByValAttr())
+ return Dunno;
+
+ PointerType *PT = cast<PointerType>(A->getType());
+ Size = TD->getTypeAllocSize(PT->getElementType());
+ return Const;
+
// ptr = select(ptr1, ptr2)
} else if (SelectInst *SI = dyn_cast<SelectInst>(Alloc)) {
uint64_t SizeFalse;
diff --git a/test/Transforms/BoundsChecking/simple.ll b/test/Transforms/BoundsChecking/simple.ll
index f24d9e1f8d..62c2e9026b 100644
--- a/test/Transforms/BoundsChecking/simple.ll
+++ b/test/Transforms/BoundsChecking/simple.ll
@@ -107,3 +107,12 @@ define void @f10(i64 %x, i64 %y) nounwind {
%4 = load i128* %3, align 4
ret void
}
+
+; CHECK: @f11
+define void @f11(i128* byval %x) nounwind {
+ %1 = bitcast i128* %x to i8*
+ %2 = getelementptr inbounds i8* %1, i64 16
+; CHECK: br label
+ %3 = load i8* %2, align 4
+ ret void
+}