forked from OSchip/llvm-project
fix PR6305 by handling BlockAddress in a helper function
called by jump threading. llvm-svn: 96263
This commit is contained in:
parent
5e73ff2e3a
commit
6fbfe5897c
|
@ -491,6 +491,17 @@ void llvm::MergeBasicBlockIntoOnlyPred(BasicBlock *DestBB, Pass *P) {
|
||||||
PredBB->getTerminator()->eraseFromParent();
|
PredBB->getTerminator()->eraseFromParent();
|
||||||
DestBB->getInstList().splice(DestBB->begin(), PredBB->getInstList());
|
DestBB->getInstList().splice(DestBB->begin(), PredBB->getInstList());
|
||||||
|
|
||||||
|
// Zap anything that took the address of DestBB. Not doing this will give the
|
||||||
|
// address an invalid value.
|
||||||
|
if (DestBB->hasAddressTaken()) {
|
||||||
|
BlockAddress *BA = BlockAddress::get(DestBB);
|
||||||
|
Constant *Replacement =
|
||||||
|
ConstantInt::get(llvm::Type::getInt32Ty(BA->getContext()), 1);
|
||||||
|
BA->replaceAllUsesWith(ConstantExpr::getIntToPtr(Replacement,
|
||||||
|
BA->getType()));
|
||||||
|
BA->destroyConstant();
|
||||||
|
}
|
||||||
|
|
||||||
// Anything that branched to PredBB now branches to DestBB.
|
// Anything that branched to PredBB now branches to DestBB.
|
||||||
PredBB->replaceAllUsesWith(DestBB);
|
PredBB->replaceAllUsesWith(DestBB);
|
||||||
|
|
||||||
|
|
|
@ -9,14 +9,18 @@ target triple = "i386-apple-darwin10.0"
|
||||||
|
|
||||||
define void @test(i32 %i) nounwind ssp {
|
define void @test(i32 %i) nounwind ssp {
|
||||||
entry:
|
entry:
|
||||||
|
call void @test(i32 1)
|
||||||
br label %foo
|
br label %foo
|
||||||
|
|
||||||
foo: ; preds = %indirectgoto, %indirectgoto, %indirectgoto, %indirectgoto, %indirectgoto
|
foo:
|
||||||
|
call void @test(i32 1)
|
||||||
br label %bar
|
br label %bar
|
||||||
|
|
||||||
bar: ; preds = %foo, %indirectgoto
|
bar:
|
||||||
|
call void @test(i32 1)
|
||||||
br label %hack
|
br label %hack
|
||||||
|
|
||||||
hack: ; preds = %bar, %indirectgoto
|
hack:
|
||||||
|
call void @test(i32 1)
|
||||||
ret void
|
ret void
|
||||||
}
|
}
|
||||||
|
|
|
@ -313,3 +313,14 @@ for.cond: ; preds = %for.body, %lor.end
|
||||||
for.body: ; preds = %for.cond
|
for.body: ; preds = %for.cond
|
||||||
br label %for.cond
|
br label %for.cond
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
; PR6305
|
||||||
|
define void @test11() nounwind {
|
||||||
|
entry:
|
||||||
|
br label %A
|
||||||
|
|
||||||
|
A: ; preds = %entry
|
||||||
|
call void undef(i64 ptrtoint (i8* blockaddress(@test11, %A) to i64)) nounwind
|
||||||
|
unreachable
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue