Skip to content

Commit 36c4512

Browse files
authored
Merge pull request #38954 from eeckstein/fix-loadablebyaddress-5.5
[5.5] LoadableByAddress: fix handling of yield instructions which can result in invalid SIL
2 parents 7105644 + d767404 commit 36c4512

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

lib/IRGen/LoadableByAddress.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2069,6 +2069,11 @@ static void rewriteFunction(StructLoweringState &pass,
20692069
pass.applies.append(currentModApplies.begin(), currentModApplies.end());
20702070
} while (repeat);
20712071

2072+
while (!pass.modYieldInsts.empty()) {
2073+
YieldInst *inst = pass.modYieldInsts.pop_back_val();
2074+
allocateAndSetAll(pass, allocator, inst, inst->getAllOperands());
2075+
}
2076+
20722077
for (SILInstruction *instr : pass.instsToMod) {
20732078
for (Operand &operand : instr->getAllOperands()) {
20742079
auto currOperand = operand.get();
@@ -2324,11 +2329,6 @@ static void rewriteFunction(StructLoweringState &pass,
23242329
retBuilder.createReturn(newRetTuple->getLoc(), newRetTuple);
23252330
instr->eraseFromParent();
23262331
}
2327-
2328-
while (!pass.modYieldInsts.empty()) {
2329-
YieldInst *inst = pass.modYieldInsts.pop_back_val();
2330-
allocateAndSetAll(pass, allocator, inst, inst->getAllOperands());
2331-
}
23322332
}
23332333

23342334
// Rewrite function return argument if it is a "function pointer"

test/IRGen/big_types_coroutine.sil

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,24 @@ bb2:
9797
abort_apply %4
9898
unwind
9999
}
100+
101+
// CHECK-LABEL: sil @test_yield_and_retain
102+
// CHECK: [[S:%[0-9]+]] = alloc_stack $BigStruct
103+
// CHECK: copy_addr [take] %0 to [initialization] [[S]]
104+
// CHECK: retain_value_addr [[S]]
105+
// CHECK: yield [[S]] : $*BigStruct
106+
// CHECK: // end sil function 'test_yield_and_retain'
107+
sil @test_yield_and_retain : $@convention(thin) @yield_once (@in_guaranteed BigStruct) -> @yields BigStruct {
108+
entry(%0 : $*BigStruct):
109+
%big = load %0 : $*BigStruct
110+
retain_value %big : $BigStruct
111+
yield %big : $BigStruct, resume resume, unwind unwind
112+
113+
resume:
114+
%ret = tuple ()
115+
return %ret : $()
116+
117+
unwind:
118+
unwind
119+
}
120+

0 commit comments

Comments
 (0)