diff options
author | Shoaib Meenai <smeenai@fb.com> | 2018-05-04 19:03:11 +0000 |
---|---|---|
committer | Shoaib Meenai <smeenai@fb.com> | 2018-05-04 19:03:11 +0000 |
commit | 57fadab1cbe319958e3da8700ab38a91fde82c53 (patch) | |
tree | 2d3eb8d7356065b5d87a580bf0007b5f51f9f358 /llvm/lib/Transforms/ObjCARC | |
parent | 7acc81b74428660efa5156815eebaee8a2ebe075 (diff) | |
download | bcm5719-llvm-57fadab1cbe319958e3da8700ab38a91fde82c53.tar.gz bcm5719-llvm-57fadab1cbe319958e3da8700ab38a91fde82c53.zip |
[ObjCARC] Account for catchswitch in bitcast insertion
A catchswitch is both a pad and a terminator, meaning it must be the
only non-phi instruction in its basic block. When we're inserting a
bitcast in the incoming basic block for a phi, if that incoming block is
a catchswitch, we should go up the dominator tree to find a valid
insertion point rather than attempting to insert before the catchswitch
(which would result in invalid IR).
Differential Revision: https://reviews.llvm.org/D46412
llvm-svn: 331548
Diffstat (limited to 'llvm/lib/Transforms/ObjCARC')
-rw-r--r-- | llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp b/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp index c0e33c4db40..bab2d1c585d 100644 --- a/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp +++ b/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp @@ -606,14 +606,27 @@ bool ObjCARCContract::runOnFunction(Function &F) { if (PHINode *PHI = dyn_cast<PHINode>(U.getUser())) { // 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()); + BasicBlock *IncomingBB = PHI->getIncomingBlock(ValNo); + if (Replacement->getType() != UseTy) { + // A catchswitch is both a pad and a terminator, meaning a basic + // block with a catchswitch has no insertion point. Keep going up + // the dominator tree until we find a non-catchswitch. + BasicBlock *InsertBB = IncomingBB; + while (isa<CatchSwitchInst>(InsertBB->getFirstNonPHI())) { + InsertBB = DT->getNode(InsertBB)->getIDom()->getBlock(); + } + + assert(DT->dominates(Inst, &InsertBB->back()) && + "Invalid insertion point for bitcast"); + Replacement = + new BitCastInst(Replacement, UseTy, "", &InsertBB->back()); + } + // While we're here, rewrite all edges for this PHI, rather // than just one use at a time, to minimize the number of // bitcasts we emit. for (unsigned i = 0, e = PHI->getNumIncomingValues(); i != e; ++i) - if (PHI->getIncomingBlock(i) == BB) { + if (PHI->getIncomingBlock(i) == IncomingBB) { // Keep the UI iterator valid. if (UI != UE && &PHI->getOperandUse( |