[PATCH] D95019: [ConstantHoisting] Fix bug where constant materialization could insert into EH pad
Michael Holman via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 19 21:27:13 PST 2021
Holman created this revision.
Holman added a reviewer: rnk.
Herald added a subscriber: hiraditya.
Holman requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
If the incoming block to a phi node is an EH pad, then we will materialize into an EH pad, which is not supposed to happen. To fix this, I added a check to see if incoming block of a phi node is an EH pad before using it as the insertion point.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D95019
Files:
llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
Index: llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
+++ llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
@@ -185,13 +185,20 @@
// We can't insert directly before a phi node or an eh pad. Insert before
// the terminator of the incoming or dominating block.
assert(Entry != Inst->getParent() && "PHI or landing pad in entry block!");
- if (Idx != ~0U && isa<PHINode>(Inst))
- return cast<PHINode>(Inst)->getIncomingBlock(Idx)->getTerminator();
+ BasicBlock *InsertionBlock = nullptr;
+ if (Idx != ~0U && isa<PHINode>(Inst)) {
+ auto InsertionBlock = cast<PHINode>(Inst)->getIncomingBlock(Idx);
+ if (!InsertionBlock->isEHPad()) {
+ return InsertionBlock->getTerminator();
+ }
+ } else {
+ InsertionBlock = Inst->getParent();
+ }
// This must be an EH pad. Iterate over immediate dominators until we find a
// non-EH pad. We need to skip over catchswitch blocks, which are both EH pads
// and terminators.
- auto IDom = DT->getNode(Inst->getParent())->getIDom();
+ auto IDom = DT->getNode(InsertionBlock)->getIDom();
while (IDom->getBlock()->isEHPad()) {
assert(Entry != IDom->getBlock() && "eh pad in entry block");
IDom = IDom->getIDom();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95019.317715.patch
Type: text/x-patch
Size: 1320 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210120/6ba6fb77/attachment.bin>
More information about the llvm-commits
mailing list