Skip to content

Commit 9861217

Browse files
committed
Devirtualizer: fix de-virtualization of begin_apply
Handle the special case of an guaranteed return value with no uses. Fixes an assertion crash. Unfortunately I don't have an isolated test case for this. But this problem showed up in the `Interpreter/moveonly_read_modify_coroutines.swift` test with OSSA modules and will therefore be tested by this test once we enable OSSA modules.
1 parent e4887c7 commit 9861217

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lib/SILOptimizer/Utils/Devirtualize.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -633,11 +633,13 @@ replaceBeginApplyInst(SILBuilder &builder, SILPassManager *pm, SILLocation loc,
633633
// Insert any end_borrow if the yielded value before the token's uses.
634634
SmallVector<SILInstruction *, 4> users(
635635
makeUserIteratorRange(oldYield->getUses()));
636-
auto yieldCastRes = castValueToABICompatibleType(
637-
&builder, pm, loc, newYield, newYield->getType(), oldYield->getType(),
638-
users);
639-
oldYield->replaceAllUsesWith(yieldCastRes.first);
640-
changedCFG |= yieldCastRes.second;
636+
if (!users.empty()) {
637+
auto yieldCastRes = castValueToABICompatibleType(
638+
&builder, pm, loc, newYield, newYield->getType(), oldYield->getType(),
639+
users);
640+
oldYield->replaceAllUsesWith(yieldCastRes.first);
641+
changedCFG |= yieldCastRes.second;
642+
}
641643
}
642644

643645
if (newArgBorrows.empty())

0 commit comments

Comments
 (0)