Skip to content

[5.5] LoadableByAddress: fix handling of yield instructions which can result in invalid SIL #38954

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 5 additions & 5 deletions lib/IRGen/LoadableByAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2069,6 +2069,11 @@ static void rewriteFunction(StructLoweringState &pass,
pass.applies.append(currentModApplies.begin(), currentModApplies.end());
} while (repeat);

while (!pass.modYieldInsts.empty()) {
YieldInst *inst = pass.modYieldInsts.pop_back_val();
allocateAndSetAll(pass, allocator, inst, inst->getAllOperands());
}

for (SILInstruction *instr : pass.instsToMod) {
for (Operand &operand : instr->getAllOperands()) {
auto currOperand = operand.get();
Expand Down Expand Up @@ -2324,11 +2329,6 @@ static void rewriteFunction(StructLoweringState &pass,
retBuilder.createReturn(newRetTuple->getLoc(), newRetTuple);
instr->eraseFromParent();
}

while (!pass.modYieldInsts.empty()) {
YieldInst *inst = pass.modYieldInsts.pop_back_val();
allocateAndSetAll(pass, allocator, inst, inst->getAllOperands());
}
}

// Rewrite function return argument if it is a "function pointer"
Expand Down
21 changes: 21 additions & 0 deletions test/IRGen/big_types_coroutine.sil
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,24 @@ bb2:
abort_apply %4
unwind
}

// CHECK-LABEL: sil @test_yield_and_retain
// CHECK: [[S:%[0-9]+]] = alloc_stack $BigStruct
// CHECK: copy_addr [take] %0 to [initialization] [[S]]
// CHECK: retain_value_addr [[S]]
// CHECK: yield [[S]] : $*BigStruct
// CHECK: // end sil function 'test_yield_and_retain'
sil @test_yield_and_retain : $@convention(thin) @yield_once (@in_guaranteed BigStruct) -> @yields BigStruct {
entry(%0 : $*BigStruct):
%big = load %0 : $*BigStruct
retain_value %big : $BigStruct
yield %big : $BigStruct, resume resume, unwind unwind

resume:
%ret = tuple ()
return %ret : $()

unwind:
unwind
}