Skip to content

Commit ce795a6

Browse files
committed
Fix OSSA RAUW perform() to handle replaceAllUsesWith for terminators
1 parent 5494592 commit ce795a6

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/SILOptimizer/Utils/OwnershipOptUtils.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,8 +1464,13 @@ OwnershipRAUWHelper::perform(SILValue replacementValue) {
14641464
// Make sure to always clear our context after we transform.
14651465
SWIFT_DEFER { ctx->clear(); };
14661466

1467-
auto *svi = dyn_cast<SingleValueInstruction>(oldValue);
1468-
return replaceAllUsesAndErase(svi, replacementValue, ctx->callbacks);
1467+
if (auto *svi = dyn_cast<SingleValueInstruction>(oldValue))
1468+
return replaceAllUsesAndErase(svi, replacementValue, ctx->callbacks);
1469+
1470+
// The caller must rewrite the terminator after RAUW.
1471+
auto *term = cast<SILPhiArgument>(oldValue)->getTerminatorForResult();
1472+
auto nextII = term->getParent()->end();
1473+
return replaceAllUses(oldValue, replacementValue, nextII, ctx->callbacks);
14691474
}
14701475

14711476
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)