[llvm-commits] [llvm] r159055 - /llvm/trunk/lib/Transforms/Scalar/BoundsChecking.cpp

Nuno Lopes nunoplopes at sapo.pt
Fri Jun 22 17:12:34 PDT 2012


Author: nlopes
Date: Fri Jun 22 19:12:34 2012
New Revision: 159055

URL: http://llvm.org/viewvc/llvm-project?rev=159055&view=rev
Log:
BoundsChecking: attach debug info to traps to make my life a bit more sane

Modified:
    llvm/trunk/lib/Transforms/Scalar/BoundsChecking.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/BoundsChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/BoundsChecking.cpp?rev=159055&r1=159054&r2=159055&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/BoundsChecking.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/BoundsChecking.cpp Fri Jun 22 19:12:34 2012
@@ -54,7 +54,7 @@
     const TargetData *TD;
     ObjectSizeOffsetEvaluator *ObjSizeEval;
     BuilderTy *Builder;
-    Function *Fn;
+    Instruction *Inst;
     BasicBlock *TrapBB;
     unsigned Penalty;
 
@@ -80,6 +80,7 @@
   if (TrapBB && SingleTrapBB)
     return TrapBB;
 
+  Function *Fn = Inst->getParent()->getParent();
   BasicBlock::iterator PrevInsertPoint = Builder->GetInsertPoint();
   TrapBB = BasicBlock::Create(Fn->getContext(), "trap", Fn);
   Builder->SetInsertPoint(TrapBB);
@@ -88,6 +89,7 @@
   CallInst *TrapCall = Builder->CreateCall(F);
   TrapCall->setDoesNotReturn();
   TrapCall->setDoesNotThrow();
+  TrapCall->setDebugLoc(Inst->getDebugLoc());
   Builder->CreateUnreachable();
 
   Builder->SetInsertPoint(PrevInsertPoint);
@@ -140,7 +142,7 @@
   Value *Size   = SizeOffset.first;
   Value *Offset = SizeOffset.second;
 
-  IntegerType *IntTy = TD->getIntPtrType(Fn->getContext());
+  IntegerType *IntTy = TD->getIntPtrType(Inst->getContext());
   Value *NeededSizeVal = ConstantInt::get(IntTy, NeededSize);
 
   // three checks are required to ensure safety:
@@ -163,7 +165,6 @@
   TD = &getAnalysis<TargetData>();
 
   TrapBB = 0;
-  Fn = &F;
   BuilderTy TheBuilder(F.getContext(), TargetFolder(TD));
   Builder = &TheBuilder;
   ObjectSizeOffsetEvaluator TheObjSizeEval(TD, F.getContext());
@@ -182,16 +183,16 @@
   bool MadeChange = false;
   for (std::vector<Instruction*>::iterator i = WorkList.begin(),
        e = WorkList.end(); i != e; ++i) {
-    Instruction *I = *i;
+    Inst = *i;
 
-    Builder->SetInsertPoint(I);
-    if (LoadInst *LI = dyn_cast<LoadInst>(I)) {
+    Builder->SetInsertPoint(Inst);
+    if (LoadInst *LI = dyn_cast<LoadInst>(Inst)) {
       MadeChange |= instrument(LI->getPointerOperand(), LI);
-    } else if (StoreInst *SI = dyn_cast<StoreInst>(I)) {
+    } else if (StoreInst *SI = dyn_cast<StoreInst>(Inst)) {
       MadeChange |= instrument(SI->getPointerOperand(), SI->getValueOperand());
-    } else if (AtomicCmpXchgInst *AI = dyn_cast<AtomicCmpXchgInst>(I)) {
+    } else if (AtomicCmpXchgInst *AI = dyn_cast<AtomicCmpXchgInst>(Inst)) {
       MadeChange |= instrument(AI->getPointerOperand(),AI->getCompareOperand());
-    } else if (AtomicRMWInst *AI = dyn_cast<AtomicRMWInst>(I)) {
+    } else if (AtomicRMWInst *AI = dyn_cast<AtomicRMWInst>(Inst)) {
       MadeChange |= instrument(AI->getPointerOperand(), AI->getValOperand());
     } else {
       llvm_unreachable("unknown Instruction type");





More information about the llvm-commits mailing list