[llvm-commits] [llvm] r152803 - in /llvm/trunk: lib/Transforms/Scalar/ObjCARC.cpp test/Transforms/ObjCARC/pr12270.ll
Rafael Espindola
rafael.espindola at gmail.com
Thu Mar 15 08:52:59 PDT 2012
Author: rafael
Date: Thu Mar 15 10:52:59 2012
New Revision: 152803
URL: http://llvm.org/viewvc/llvm-project?rev=152803&view=rev
Log:
Short term fix for pr12270 before we change dominates to handle unreachable
code.
While here, reduce indentation.
Added:
llvm/trunk/test/Transforms/ObjCARC/pr12270.ll
Modified:
llvm/trunk/lib/Transforms/Scalar/ObjCARC.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/ObjCARC.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/ObjCARC.cpp?rev=152803&r1=152802&r2=152803&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/ObjCARC.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/ObjCARC.cpp Thu Mar 15 10:52:59 2012
@@ -4024,36 +4024,40 @@
Use &U = UI.getUse();
unsigned OperandNo = UI.getOperandNo();
++UI; // Increment UI now, because we may unlink its element.
- if (Instruction *UserInst = dyn_cast<Instruction>(U.getUser()))
- if (Inst != UserInst && DT->dominates(Inst, UserInst)) {
- Changed = true;
- Instruction *Replacement = Inst;
- Type *UseTy = U.get()->getType();
- if (PHINode *PHI = dyn_cast<PHINode>(UserInst)) {
- // For PHI nodes, insert the bitcast in the predecessor block.
- unsigned ValNo =
- PHINode::getIncomingValueNumForOperand(OperandNo);
- BasicBlock *BB =
- PHI->getIncomingBlock(ValNo);
- if (Replacement->getType() != UseTy)
- Replacement = new BitCastInst(Replacement, UseTy, "",
- &BB->back());
- for (unsigned i = 0, e = PHI->getNumIncomingValues();
- i != e; ++i)
- if (PHI->getIncomingBlock(i) == BB) {
- // Keep the UI iterator valid.
- if (&PHI->getOperandUse(
- PHINode::getOperandNumForIncomingValue(i)) ==
- &UI.getUse())
- ++UI;
- PHI->setIncomingValue(i, Replacement);
- }
- } else {
- if (Replacement->getType() != UseTy)
- Replacement = new BitCastInst(Replacement, UseTy, "", UserInst);
- U.set(Replacement);
- }
+ Instruction *UserInst = dyn_cast<Instruction>(U.getUser());
+ if (!UserInst)
+ continue;
+ // FIXME: dominates should return true for unreachable UserInst.
+ if (!DT->isReachableFromEntry(UserInst->getParent()) ||
+ DT->dominates(Inst, UserInst)) {
+ Changed = true;
+ Instruction *Replacement = Inst;
+ Type *UseTy = U.get()->getType();
+ if (PHINode *PHI = dyn_cast<PHINode>(UserInst)) {
+ // For PHI nodes, insert the bitcast in the predecessor block.
+ unsigned ValNo =
+ PHINode::getIncomingValueNumForOperand(OperandNo);
+ BasicBlock *BB =
+ PHI->getIncomingBlock(ValNo);
+ if (Replacement->getType() != UseTy)
+ Replacement = new BitCastInst(Replacement, UseTy, "",
+ &BB->back());
+ for (unsigned i = 0, e = PHI->getNumIncomingValues();
+ i != e; ++i)
+ if (PHI->getIncomingBlock(i) == BB) {
+ // Keep the UI iterator valid.
+ if (&PHI->getOperandUse(
+ PHINode::getOperandNumForIncomingValue(i)) ==
+ &UI.getUse())
+ ++UI;
+ PHI->setIncomingValue(i, Replacement);
+ }
+ } else {
+ if (Replacement->getType() != UseTy)
+ Replacement = new BitCastInst(Replacement, UseTy, "", UserInst);
+ U.set(Replacement);
}
+ }
}
// If Arg is a no-op casted pointer, strip one level of casts and
Added: llvm/trunk/test/Transforms/ObjCARC/pr12270.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/ObjCARC/pr12270.ll?rev=152803&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/ObjCARC/pr12270.ll (added)
+++ llvm/trunk/test/Transforms/ObjCARC/pr12270.ll Thu Mar 15 10:52:59 2012
@@ -0,0 +1,15 @@
+; RUN: opt -disable-output -objc-arc-contract %s
+; test that we don't crash on unreachable code
+%2 = type opaque
+
+define void @_i_Test__foo(%2 *%x) {
+entry:
+ unreachable
+
+return: ; No predecessors!
+ %bar = bitcast %2* %x to i8*
+ %foo = call i8* @objc_autoreleaseReturnValue(i8* %bar) nounwind
+ ret void
+}
+
+declare i8* @objc_autoreleaseReturnValue(i8*)
More information about the llvm-commits
mailing list