Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions llvm/lib/Analysis/ScalarEvolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15445,6 +15445,12 @@ void ScalarEvolution::LoopGuards::collectFromPHI(
const BasicBlock *InBlock = Phi.getIncomingBlock(IncomingIdx);
if (!VisitedBlocks.insert(InBlock).second)
return {nullptr, scCouldNotCompute};

// Avoid analyzing unreachable blocks so that we don't get trapped
// traversing cycles with ill-formed dominance or infinite cycles
if (!SE.DT.isReachableFromEntry(InBlock))
return {nullptr, scCouldNotCompute};

auto [G, Inserted] = IncomingGuards.try_emplace(InBlock, LoopGuards(SE));
if (Inserted)
collectFromBlock(SE, G->second, Phi.getParent(), InBlock, VisitedBlocks,
Expand Down Expand Up @@ -15499,6 +15505,9 @@ void ScalarEvolution::LoopGuards::collectFromBlock(
ScalarEvolution &SE, ScalarEvolution::LoopGuards &Guards,
const BasicBlock *Block, const BasicBlock *Pred,
SmallPtrSetImpl<const BasicBlock *> &VisitedBlocks, unsigned Depth) {

assert(SE.DT.isReachableFromEntry(Block) && SE.DT.isReachableFromEntry(Pred));

SmallVector<const SCEV *> ExprsToRewrite;
auto CollectCondition = [&](ICmpInst::Predicate Predicate, const SCEV *LHS,
const SCEV *RHS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,3 +364,34 @@ body:
exit:
ret void
}

define void @hang_due_to_unreachable_phi_inblock() personality ptr null {
br label %1

1: ; preds = %1, %0
%2 = invoke ptr null(i64 0)
to label %1 unwind label %3

3: ; preds = %1
%4 = landingpad { ptr, i32 }
cleanup
br label %7

5: ; No predecessors!
%6 = landingpad { ptr, i32 }
cleanup
br label %7

7: ; preds = %5, %3
%8 = phi ptr [ null, %5 ], [ null, %3 ]
br i1 false, label %13, label %9

9: ; preds = %9, %7
%10 = phi ptr [ %11, %9 ], [ null, %7 ]
%11 = getelementptr i8, ptr %10, i64 24
%12 = icmp eq ptr %10, null
br i1 %12, label %13, label %9

13: ; preds = %9, %7
resume { ptr, i32 } zeroinitializer
}