Skip to content

Commit 78a8cac

Browse files
committed
Fix EscapeAnalysis iterator invalidation.
Noticed by code inspection during debugging. Iterator invalidaton could occur because two types of edges, which are handled independently, actually share the same phyical list. Fix the visitor utility that iterates over defer edges to be robust for visitors that change the pointsTo edge. Use a temporary vector to be safe.
1 parent 1f580be commit 78a8cac

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

lib/SILOptimizer/Analysis/EscapeAnalysis.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,10 @@ bool EscapeAnalysis::CGNode::visitSuccessors(Visitor &&visitor) const {
363363

364364
template <typename Visitor>
365365
bool EscapeAnalysis::CGNode::visitDefers(Visitor &&visitor) const {
366-
for (Predecessor pred : Preds) {
366+
// Save predecessors before calling `visitor` which may assign pointsTo edges
367+
// which invalidates the predecessor iterator.
368+
SmallVector<Predecessor, 4> predVector(Preds.begin(), Preds.end());
369+
for (Predecessor pred : predVector) {
367370
if (!pred.is(EdgeType::Defer))
368371
continue;
369372
if (!visitor(pred.getPredNode(), false))

0 commit comments

Comments
 (0)