[llvm-commits] [llvm] r96263 - in /llvm/trunk: lib/Transforms/Utils/Local.cpp test/CodeGen/X86/addr-label-difference.ll test/Transforms/JumpThreading/crash.ll

Chris Lattner sabre at nondot.org
Mon Feb 15 12:47:49 PST 2010


Author: lattner
Date: Mon Feb 15 14:47:49 2010
New Revision: 96263

URL: http://llvm.org/viewvc/llvm-project?rev=96263&view=rev
Log:
fix PR6305 by handling BlockAddress in a helper function
called by jump threading.

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

Modified: llvm/trunk/lib/Transforms/Utils/Local.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/Local.cpp?rev=96263&r1=96262&r2=96263&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Utils/Local.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/Local.cpp Mon Feb 15 14:47:49 2010
@@ -490,6 +490,17 @@
   // 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);

Modified: llvm/trunk/test/CodeGen/X86/addr-label-difference.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/addr-label-difference.ll?rev=96263&r1=96262&r2=96263&view=diff

==============================================================================
--- llvm/trunk/test/CodeGen/X86/addr-label-difference.ll (original)
+++ llvm/trunk/test/CodeGen/X86/addr-label-difference.ll Mon Feb 15 14:47:49 2010
@@ -9,14 +9,18 @@
 
 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
 }

Modified: llvm/trunk/test/Transforms/JumpThreading/crash.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/JumpThreading/crash.ll?rev=96263&r1=96262&r2=96263&view=diff

==============================================================================
--- llvm/trunk/test/Transforms/JumpThreading/crash.ll (original)
+++ llvm/trunk/test/Transforms/JumpThreading/crash.ll Mon Feb 15 14:47:49 2010
@@ -313,3 +313,14 @@
 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
+}





More information about the llvm-commits mailing list