Skip to content

Commit e23665e

Browse files
committed
[AddressLowering] Map-into-ctx type for yield.
Previously, the type for the storage into which a loadable value which was yielded via an indirect convention was obtained from the SILFunctionConventions and the SILYieldIfo but not mapped into the context of the current function. Here, that's fixed.
1 parent a2645b7 commit e23665e

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

lib/SILOptimizer/Mandatory/AddressLowering.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2815,8 +2815,8 @@ void YieldRewriter::rewriteYield(YieldInst *yieldInst) {
28152815
void YieldRewriter::rewriteOperand(YieldInst *yieldInst, unsigned index) {
28162816
auto info = opaqueFnConv.getYieldInfoForOperandIndex(index);
28172817
auto convention = info.getConvention();
2818-
auto ty =
2819-
opaqueFnConv.getSILType(info, pass.function->getTypeExpansionContext());
2818+
auto ty = pass.function->mapTypeIntoContext(
2819+
opaqueFnConv.getSILType(info, pass.function->getTypeExpansionContext()));
28202820
if (ty.isAddressOnly(*pass.function)) {
28212821
assert(yieldInst->getOperand(index)->getType().isAddress() &&
28222822
"rewriting yield of of address-only value after use rewriting!?");

test/SILOptimizer/address_lowering.sil

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ struct LoadableNontrivial {
3737
var x: Klass
3838
}
3939

40+
struct LoadableNontrivialGeneric<T> {
41+
var x: Klass
42+
}
43+
4044
struct SI<T> {
4145
var element: T
4246
var index: I
@@ -2642,3 +2646,29 @@ unwindbb:
26422646
abort_apply %token
26432647
unwind
26442648
}
2649+
2650+
// Verify that the type of the alloc_stack is appropriately mapped into the
2651+
// function's context.
2652+
// CHECK-LABEL: sil [ossa] @test_yield_D_loadable_generic_as_inguaranteed : {{.*}} <T> {{.*}} {
2653+
// CHECK: ([[INSTANCE_ADDR:%[^,]+]], {{%[^,]+}}) = begin_apply undef<T>()
2654+
// CHECK: [[INSTANCE:%[^,]+]] = load_borrow [[INSTANCE_ADDR:%[^,]+]]
2655+
// CHECK: [[STACK_ADDR:%[^,]+]] = alloc_stack $LoadableNontrivialGeneric<T>
2656+
// ^^^ Verify that T and not τ_0_0 appears
2657+
// CHECK: [[YIELDABLE_INSTANCE:%[^,]+]] = store_borrow [[INSTANCE:%[^,]+]] to [[STACK_ADDR:%[^,]+]]
2658+
// CHECK: yield [[YIELDABLE_INSTANCE]]
2659+
// CHECK-LABEL: } // end sil function 'test_yield_D_loadable_generic_as_inguaranteed'
2660+
sil [ossa] @test_yield_D_loadable_generic_as_inguaranteed : $@yield_once @convention(thin) <T> () -> @yields @in_guaranteed LoadableNontrivialGeneric<T> {
2661+
bb0:
2662+
(%3, %4) = begin_apply undef<T>() : $@yield_once @convention(method) <Tee> () -> @yields @in_guaranteed LoadableNontrivialGeneric<Tee>
2663+
yield %3 : $LoadableNontrivialGeneric<T>, resume bb1, unwind bb2
2664+
2665+
bb1:
2666+
end_apply %4
2667+
%7 = tuple ()
2668+
return %7 : $()
2669+
2670+
bb2:
2671+
abort_apply %4
2672+
unwind
2673+
}
2674+

0 commit comments

Comments
 (0)