aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/Scalar/BoundsChecking.cpp
diff options
context:
space:
mode:
authorNuno Lopes <nunoplopes@sapo.pt>2012-06-23 00:12:34 +0000
committerNuno Lopes <nunoplopes@sapo.pt>2012-06-23 00:12:34 +0000
commit512be1f83e3481403c0ce5ce678254388a6fb852 (patch)
tree0d147810b3dcb7c18ccdfbe9cead5e477a96f30e /lib/Transforms/Scalar/BoundsChecking.cpp
parent70c9bf3c1a77b5707c92a7cfe74104c320480391 (diff)
BoundsChecking: attach debug info to traps to make my life a bit more sane
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@159055 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/BoundsChecking.cpp')
-rw-r--r--lib/Transforms/Scalar/BoundsChecking.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/lib/Transforms/Scalar/BoundsChecking.cpp b/lib/Transforms/Scalar/BoundsChecking.cpp
index 6729dd2059..ce7438cf0e 100644
--- a/lib/Transforms/Scalar/BoundsChecking.cpp
+++ b/lib/Transforms/Scalar/BoundsChecking.cpp
@@ -54,7 +54,7 @@ namespace {
const TargetData *TD;
ObjectSizeOffsetEvaluator *ObjSizeEval;
BuilderTy *Builder;
- Function *Fn;
+ Instruction *Inst;
BasicBlock *TrapBB;
unsigned Penalty;
@@ -80,6 +80,7 @@ BasicBlock *BoundsChecking::getTrapBB() {
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 @@ BasicBlock *BoundsChecking::getTrapBB() {
CallInst *TrapCall = Builder->CreateCall(F);
TrapCall->setDoesNotReturn();
TrapCall->setDoesNotThrow();
+ TrapCall->setDebugLoc(Inst->getDebugLoc());
Builder->CreateUnreachable();
Builder->SetInsertPoint(PrevInsertPoint);
@@ -140,7 +142,7 @@ bool BoundsChecking::instrument(Value *Ptr, Value *InstVal) {
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 @@ bool BoundsChecking::runOnFunction(Function &F) {
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 BoundsChecking::runOnFunction(Function &F) {
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");