Skip to content

Commit 75790dd

Browse files
authored
[RemoveDIs] Fix nullptr dereference in getFirstNonPHIIt() (llvm#84595)
getFirstNonPHI() returns nullptr for blocks that lack a non-phi (including a terminator) but getFirstNonPHIIt() may dereference its result unconditionally. Return end() instead. This came up for us downstream while correcting our getFirstNonPHI() calls that intended to return the position after the phi's but before the debug info to getFirstNonPHIIt(). The pass in question is populating new BB's and hasn't added terminators yet.
1 parent d125d55 commit 75790dd

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

llvm/lib/IR/BasicBlock.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,8 @@ const Instruction* BasicBlock::getFirstNonPHI() const {
348348

349349
BasicBlock::const_iterator BasicBlock::getFirstNonPHIIt() const {
350350
const Instruction *I = getFirstNonPHI();
351+
if (!I)
352+
return end();
351353
BasicBlock::const_iterator It = I->getIterator();
352354
// Set the head-inclusive bit to indicate that this iterator includes
353355
// any debug-info at the start of the block. This is a no-op unless the

0 commit comments

Comments
 (0)