LoopRotate: Fix a by reference map bug under reallocation

When using a densemap subscript expression on both sides of an
assignment in the same statement of the same map we run into the issue
that the map can reallocate because of the assignment but we are
referencing the value of the RHS map subscript by reference --
i.e we can reference deallocated memory.

Not good.

My attempts at making a reproducer crash failed.

rdar://151031297
This commit is contained in:
Arnold Schwaighofer
2025-06-04 10:58:33 -07:00
parent dd57d4dd85
commit 59b8813807

View File

@@ -428,7 +428,8 @@ static bool rotateLoop(SILLoop *loop, DominanceInfo *domInfo,
for (auto &inst : *header) {
if (auto *bfi = dyn_cast<BorrowedFromInst>(&inst)) {
valueMap[bfi] = valueMap[bfi->getBorrowedValue()];
auto mappedValue = valueMap[bfi->getBorrowedValue()];
valueMap[bfi] = mappedValue;
} else if (SILInstruction *cloned = inst.clone(preheaderBranch)) {
mapOperands(cloned, valueMap);