[llvm-commits] [llvm] r157498 - in /llvm/trunk: lib/Transforms/Scalar/BoundsChecking.cpp test/Transforms/BoundsChecking/simple.ll

Nuno Lopes nunoplopes at sapo.pt
Fri May 25 14:15:18 PDT 2012


Author: nlopes
Date: Fri May 25 16:15:17 2012
New Revision: 157498

URL: http://llvm.org/viewvc/llvm-project?rev=157498&view=rev
Log:
bounds checking: add support for byval arguments

Modified:
    llvm/trunk/lib/Transforms/Scalar/BoundsChecking.cpp
    llvm/trunk/test/Transforms/BoundsChecking/simple.ll

Modified: llvm/trunk/lib/Transforms/Scalar/BoundsChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/BoundsChecking.cpp?rev=157498&r1=157497&r2=157498&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/BoundsChecking.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/BoundsChecking.cpp Fri May 25 16:15:17 2012
@@ -104,7 +104,6 @@
   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 @@
     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;

Modified: llvm/trunk/test/Transforms/BoundsChecking/simple.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/BoundsChecking/simple.ll?rev=157498&r1=157497&r2=157498&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/BoundsChecking/simple.ll (original)
+++ llvm/trunk/test/Transforms/BoundsChecking/simple.ll Fri May 25 16:15:17 2012
@@ -107,3 +107,12 @@
   %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
+}





More information about the llvm-commits mailing list