summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-02-15 20:47:49 +0000
committerChris Lattner <sabre@nondot.org>2010-02-15 20:47:49 +0000
commit6fbfe5897c7b50fc209ceadf90b77d2de6ac5137 (patch)
treee24eefd0da36a3c3a21063f0c7af794a550dce33
parent5e73ff2e3a34a76ddd66b6b7439c77e43e3a0658 (diff)
downloadbcm5719-llvm-6fbfe5897c7b50fc209ceadf90b77d2de6ac5137.tar.gz
bcm5719-llvm-6fbfe5897c7b50fc209ceadf90b77d2de6ac5137.zip
fix PR6305 by handling BlockAddress in a helper function
called by jump threading. llvm-svn: 96263
-rw-r--r--llvm/lib/Transforms/Utils/Local.cpp11
-rw-r--r--llvm/test/CodeGen/X86/addr-label-difference.ll10
-rw-r--r--llvm/test/Transforms/JumpThreading/crash.ll11
3 files changed, 29 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index 7e7973ae0b7..57ad459c8e1 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -490,6 +490,17 @@ void llvm::MergeBasicBlockIntoOnlyPred(BasicBlock *DestBB, Pass *P) {
// Splice all the instructions from PredBB to DestBB.
PredBB->getTerminator()->eraseFromParent();
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.
PredBB->replaceAllUsesWith(DestBB);
diff --git a/llvm/test/CodeGen/X86/addr-label-difference.ll b/llvm/test/CodeGen/X86/addr-label-difference.ll
index 547d6b57657..be0908aa1a9 100644
--- a/llvm/test/CodeGen/X86/addr-label-difference.ll
+++ b/llvm/test/CodeGen/X86/addr-label-difference.ll
@@ -9,14 +9,18 @@ target triple = "i386-apple-darwin10.0"
define void @test(i32 %i) nounwind ssp {
entry:
+ call void @test(i32 1)
br label %foo
-foo: ; preds = %indirectgoto, %indirectgoto, %indirectgoto, %indirectgoto, %indirectgoto
+foo:
+ call void @test(i32 1)
br label %bar
-bar: ; preds = %foo, %indirectgoto
+bar:
+ call void @test(i32 1)
br label %hack
-hack: ; preds = %bar, %indirectgoto
+hack:
+ call void @test(i32 1)
ret void
}
diff --git a/llvm/test/Transforms/JumpThreading/crash.ll b/llvm/test/Transforms/JumpThreading/crash.ll
index cf292df0f71..c65fd1014be 100644
--- a/llvm/test/Transforms/JumpThreading/crash.ll
+++ b/llvm/test/Transforms/JumpThreading/crash.ll
@@ -313,3 +313,14 @@ for.cond: ; preds = %for.body, %lor.end
for.body: ; preds = %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
+}
OpenPOWER on IntegriCloud