fix PR6305 by handling BlockAddress in a helper function
authorChris Lattner <sabre@nondot.org>
Mon, 15 Feb 2010 20:47:49 +0000 (20:47 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 15 Feb 2010 20:47:49 +0000 (20:47 +0000)
called by jump threading.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96263 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Utils/Local.cpp
test/CodeGen/X86/addr-label-difference.ll
test/Transforms/JumpThreading/crash.ll

index 7e7973ae0b737b3cc76533cdc2103e039c00186e..57ad459c8e1922c075e07ffacfbf0b8afa654183 100644 (file)
@@ -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);
index 547d6b57657a7504da2f89efdaaf4348f4a492f0..be0908aa1a9d7b86e7e0851ebd340f54ff9975e7 100644 (file)
@@ -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
 }
index cf292df0f716ec112e699432ce70987e0d1e21fb..c65fd1014be4dddac31b2299e68b6d814eba4fe7 100644 (file)
@@ -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
+}