summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2012-07-16 10:01:02 +0000
committerChandler Carruth <chandlerc@gmail.com>2012-07-16 10:01:02 +0000
commit8b540ab337ea6ca1c03bec6a6c4f22666cd3026c (patch)
tree09687ce58d738c9127206a76aff1104067502770 /llvm/lib/Transforms
parent7e22282b6828d1c740ef553a596d8307f1b39bba (diff)
downloadbcm5719-llvm-8b540ab337ea6ca1c03bec6a6c4f22666cd3026c.tar.gz
bcm5719-llvm-8b540ab337ea6ca1c03bec6a6c4f22666cd3026c.zip
Revert r160254 temporarily.
It turns out that ASan relied on the at-the-end block insertion order to (purely by happenstance) disable some LLVM optimizations, which in turn start firing when the ordering is made more "normal". These optimizations in turn merge many of the instrumentation reporting calls which breaks the return address based error reporting in ASan. We're looking at several different options for fixing this. llvm-svn: 160256
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp32
1 files changed, 16 insertions, 16 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
index 45bcdf87aa4..482ebef2a23 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 *Then = Head->splitBasicBlock(SplitBefore);
- BasicBlock *Tail = Then->splitBasicBlock(SplitBefore);
-
+ BasicBlock *Tail = Head->splitBasicBlock(SplitBefore);
TerminatorInst *HeadOldTerm = Head->getTerminator();
- IRBuilder<>(HeadOldTerm).CreateCondBr(Cmp, Then, Tail);
- HeadOldTerm->eraseFromParent();
-
- return cast<BranchInst>(Then->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;
}
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);
- IRB.SetInsertPoint(CheckTerm);
+ IRBuilder<> IRB2(CheckTerm);
size_t Granularity = 1 << MappingScale;
if (TypeSize < 8 * Granularity) {
// Addr & (Granularity - 1)
- Value *LastAccessedByte = IRB.CreateAnd(
+ Value *LastAccessedByte = IRB2.CreateAnd(
AddrLong, ConstantInt::get(IntptrTy, Granularity - 1));
// (Addr & (Granularity - 1)) + size - 1
if (TypeSize / 8 > 1)
- LastAccessedByte = IRB.CreateAdd(
+ LastAccessedByte = IRB2.CreateAdd(
LastAccessedByte, ConstantInt::get(IntptrTy, TypeSize / 8 - 1));
// (uint8_t) ((Addr & (Granularity-1)) + size - 1)
- LastAccessedByte = IRB.CreateIntCast(
+ LastAccessedByte = IRB2.CreateIntCast(
LastAccessedByte, IRB.getInt8Ty(), false);
// ((uint8_t) ((Addr & (Granularity-1)) + size - 1)) >= ShadowValue
- Value *Cmp2 = IRB.CreateICmpSGE(LastAccessedByte, ShadowValue);
+ Value *Cmp2 = IRB2.CreateICmpSGE(LastAccessedByte, ShadowValue);
CheckTerm = splitBlockAndInsertIfThen(Cmp2);
- IRB.SetInsertPoint(CheckTerm);
}
- Instruction *Crash = generateCrashCode(IRB, AddrLong, IsWrite, TypeSize);
+ IRBuilder<> IRB1(CheckTerm);
+ Instruction *Crash = generateCrashCode(IRB1, AddrLong, IsWrite, TypeSize);
Crash->setDebugLoc(OrigIns->getDebugLoc());
ReplaceInstWithInst(CheckTerm, new UnreachableInst(*C));
}
OpenPOWER on IntegriCloud