Skip to content

Commit e138826

Browse files
author
Tyler Lanphear
committed
[IR] Don't skip catchswitch instructions when calling
`getFirstNonPHIOrDbgOrAlloca()` `BasicBlock::getFirstNonPHIOrDbgOrAlloca()` is supposed to yield the first instruction in the block which is not a PHI or dbg or alloca instruction. To that effect, it also skips an EHPad instruction which might be present after any PHIs. Normally, the latter is fine, but it has an unexpected interaction with `catchswitch` blocks: ``` bb: ; optional PHIs %0 = catchswitch within none [label %catch] unwind to caller ``` If we skip over the `catchswitch` instruction in the previous block, we'll return the end iterator, despite `catchswitch` not being a PHI or dbg or alloca instruction. This patch amends the logic to not skip an EHPad instruction which is also a terminator. This means that calling `getFirstNonPHIOrDbgOrAlloca()` on a non-empty block with a terminator (such as the above) will always yield a valid instruction iterator. This appears to be the expected behavior anyways, as most usages of this method do not check that the returned iterator is `end()`. Closes #136048.
1 parent 6727d58 commit e138826

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

llvm/lib/IR/BasicBlock.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ BasicBlock::const_iterator BasicBlock::getFirstNonPHIOrDbgOrAlloca() const {
455455
if (InsertPt == end())
456456
return end();
457457

458-
if (InsertPt->isEHPad())
458+
if (InsertPt->isEHPad() && !InsertPt->isTerminator())
459459
++InsertPt;
460460

461461
if (isEntryBlock()) {

0 commit comments

Comments
 (0)