diff options
| author | Chandler Carruth <chandlerc@gmail.com> | 2012-07-16 08:58:53 +0000 |
|---|---|---|
| committer | Chandler Carruth <chandlerc@gmail.com> | 2012-07-16 08:58:53 +0000 |
| commit | 3dd6c81492cb044b973f2e023423f667692b5bbd (patch) | |
| tree | 438b46c11bc8fed0854a36f94435f70e4f3046da /llvm/lib | |
| parent | 663943e23eea2071d299686c3c40f63a919dc5c1 (diff) | |
| download | bcm5719-llvm-3dd6c81492cb044b973f2e023423f667692b5bbd.tar.gz bcm5719-llvm-3dd6c81492cb044b973f2e023423f667692b5bbd.zip | |
Teach AddressSanitizer to create basic blocks in a more natural order.
This is particularly useful to the backend code generators which try to
process things in the incoming function order.
Also, cleanup some uses of IRBuilder to be a bit simpler and more clear.
llvm-svn: 160254
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp index 482ebef2a23..45bcdf87aa4 100644 --- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -230,17 +230,17 @@ static GlobalVariable *createPrivateGlobalForString(Module &M, StringRef Str) { // Returns the ThenBlock's terminator. static BranchInst *splitBlockAndInsertIfThen(Value *Cmp) { Instruction *SplitBefore = cast<Instruction>(Cmp)->getNextNode(); + + // Create three basic blocks, with the middle block empty, by splitting twice. BasicBlock *Head = SplitBefore->getParent(); - BasicBlock *Tail = Head->splitBasicBlock(SplitBefore); + BasicBlock *Then = Head->splitBasicBlock(SplitBefore); + BasicBlock *Tail = Then->splitBasicBlock(SplitBefore); + TerminatorInst *HeadOldTerm = Head->getTerminator(); - 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, ThenBlock); - return CheckTerm; + IRBuilder<>(HeadOldTerm).CreateCondBr(Cmp, Then, Tail); + HeadOldTerm->eraseFromParent(); + + return cast<BranchInst>(Then->getTerminator()); } Value *AddressSanitizer::memToShadow(Value *Shadow, IRBuilder<> &IRB) { @@ -387,28 +387,28 @@ void AddressSanitizer::instrumentAddress(Instruction *OrigIns, Value *Cmp = IRB.CreateICmpNE(ShadowValue, CmpVal); Instruction *CheckTerm = splitBlockAndInsertIfThen(Cmp); - IRBuilder<> IRB2(CheckTerm); + IRB.SetInsertPoint(CheckTerm); size_t Granularity = 1 << MappingScale; if (TypeSize < 8 * Granularity) { // Addr & (Granularity - 1) - Value *LastAccessedByte = IRB2.CreateAnd( + Value *LastAccessedByte = IRB.CreateAnd( AddrLong, ConstantInt::get(IntptrTy, Granularity - 1)); // (Addr & (Granularity - 1)) + size - 1 if (TypeSize / 8 > 1) - LastAccessedByte = IRB2.CreateAdd( + LastAccessedByte = IRB.CreateAdd( LastAccessedByte, ConstantInt::get(IntptrTy, TypeSize / 8 - 1)); // (uint8_t) ((Addr & (Granularity-1)) + size - 1) - LastAccessedByte = IRB2.CreateIntCast( + LastAccessedByte = IRB.CreateIntCast( LastAccessedByte, IRB.getInt8Ty(), false); // ((uint8_t) ((Addr & (Granularity-1)) + size - 1)) >= ShadowValue - Value *Cmp2 = IRB2.CreateICmpSGE(LastAccessedByte, ShadowValue); + Value *Cmp2 = IRB.CreateICmpSGE(LastAccessedByte, ShadowValue); CheckTerm = splitBlockAndInsertIfThen(Cmp2); + IRB.SetInsertPoint(CheckTerm); } - IRBuilder<> IRB1(CheckTerm); - Instruction *Crash = generateCrashCode(IRB1, AddrLong, IsWrite, TypeSize); + Instruction *Crash = generateCrashCode(IRB, AddrLong, IsWrite, TypeSize); Crash->setDebugLoc(OrigIns->getDebugLoc()); ReplaceInstWithInst(CheckTerm, new UnreachableInst(*C)); } |

