diff options
author | Kostya Serebryany <kcc@google.com> | 2012-07-02 11:42:29 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2012-07-02 11:42:29 +0000 |
commit | 56139bc493790612ee6281630678e293be6b2eb2 (patch) | |
tree | 73baafcb9eac6ddae5f1fd6038cbdd777bbeb005 /lib/Transforms/Instrumentation/AddressSanitizer.cpp | |
parent | 7e621f3242108121139c81e9f71f0e15a4d0aa76 (diff) |
[asan] small code simplification
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@159522 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Instrumentation/AddressSanitizer.cpp')
-rw-r--r-- | lib/Transforms/Instrumentation/AddressSanitizer.cpp | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/lib/Transforms/Instrumentation/AddressSanitizer.cpp index 6436dcb30a..482ebef2a2 100644 --- a/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ b/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -157,7 +157,6 @@ struct AddressSanitizer : public ModulePass { bool poisonStackInFunction(Module &M, Function &F); virtual bool runOnModule(Module &M); bool insertGlobalRedzones(Module &M); - BranchInst *splitBlockAndInsertIfThen(Instruction *SplitBefore, Value *Cmp); static char ID; // Pass identification, replacement for typeid private: @@ -220,29 +219,27 @@ static GlobalVariable *createPrivateGlobalForString(Module &M, StringRef Str) { // Split the basic block and insert an if-then code. // Before: // Head -// SplitBefore +// Cmp // Tail // After: // Head // if (Cmp) -// NewBasicBlock -// SplitBefore +// ThenBlock // Tail // -// Returns the NewBasicBlock's terminator. -BranchInst *AddressSanitizer::splitBlockAndInsertIfThen( - Instruction *SplitBefore, Value *Cmp) { +// Returns the ThenBlock's terminator. +static BranchInst *splitBlockAndInsertIfThen(Value *Cmp) { + Instruction *SplitBefore = cast<Instruction>(Cmp)->getNextNode(); BasicBlock *Head = SplitBefore->getParent(); BasicBlock *Tail = Head->splitBasicBlock(SplitBefore); TerminatorInst *HeadOldTerm = Head->getTerminator(); - BasicBlock *NewBasicBlock = - BasicBlock::Create(*C, "", Head->getParent()); - BranchInst *HeadNewTerm = BranchInst::Create(/*ifTrue*/NewBasicBlock, - /*ifFalse*/Tail, - Cmp); + LLVMContext &C = Head->getParent()->getParent()->getContext(); + BasicBlock *ThenBlock = BasicBlock::Create(C, "", Head->getParent()); + BranchInst *HeadNewTerm = + BranchInst::Create(/*ifTrue*/ThenBlock, /*ifFalse*/Tail, Cmp); ReplaceInstWithInst(HeadOldTerm, HeadNewTerm); - BranchInst *CheckTerm = BranchInst::Create(Tail, NewBasicBlock); + BranchInst *CheckTerm = BranchInst::Create(Tail, ThenBlock); return CheckTerm; } @@ -291,8 +288,8 @@ bool AddressSanitizer::instrumentMemIntrinsic(MemIntrinsic *MI) { IRBuilder<> IRB(InsertBefore); Value *Cmp = IRB.CreateICmpNE(Length, - Constant::getNullValue(Length->getType())); - InsertBefore = splitBlockAndInsertIfThen(InsertBefore, Cmp); + Constant::getNullValue(Length->getType())); + InsertBefore = splitBlockAndInsertIfThen(Cmp); } instrumentMemIntrinsicParam(MI, Dst, Length, InsertBefore, true); @@ -389,8 +386,7 @@ void AddressSanitizer::instrumentAddress(Instruction *OrigIns, Value *Cmp = IRB.CreateICmpNE(ShadowValue, CmpVal); - Instruction *CheckTerm = splitBlockAndInsertIfThen( - cast<Instruction>(Cmp)->getNextNode(), Cmp); + Instruction *CheckTerm = splitBlockAndInsertIfThen(Cmp); IRBuilder<> IRB2(CheckTerm); size_t Granularity = 1 << MappingScale; @@ -408,7 +404,7 @@ void AddressSanitizer::instrumentAddress(Instruction *OrigIns, // ((uint8_t) ((Addr & (Granularity-1)) + size - 1)) >= ShadowValue Value *Cmp2 = IRB2.CreateICmpSGE(LastAccessedByte, ShadowValue); - CheckTerm = splitBlockAndInsertIfThen(CheckTerm, Cmp2); + CheckTerm = splitBlockAndInsertIfThen(Cmp2); } IRBuilder<> IRB1(CheckTerm); |