Skip to content

Commit e41c237

Browse files
committed
GenericCloner: copy effects from the original function to the generic specialization
1 parent a2c2985 commit e41c237

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

lib/SILOptimizer/Utils/GenericCloner.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ SILFunction *GenericCloner::createDeclaration(
5252
if (!Orig->hasOwnership()) {
5353
NewF->setOwnershipEliminated();
5454
}
55+
NewF->copyEffects(Orig);
5556
return NewF;
5657
}
5758

test/SILOptimizer/specialize_reabstraction.sil

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: %target-sil-opt -enable-sil-verify-all -generic-specializer %s | %FileCheck %s
22

3+
// REQUIRES: swift_in_compiler
34

45
sil_stage canonical
56

@@ -35,6 +36,8 @@ public struct Val<T> : ValProto {
3536
init()
3637
}
3738

39+
class X {}
40+
3841
sil @coerce : $@convention(thin) <T, U, V> (@owned @callee_owned (@owned Ref<T>) -> @owned @callee_owned (@owned Ref<U>) -> @owned Ref<V>) -> @owned @callee_owned (Val<U>) -> Val<V>
3942

4043
sil @merge : $@convention(method) <Self where Self : RefProto><U> (@owned Ref<U>, @in_guaranteed Self) -> @owned Ref<(Self.T, U)> {
@@ -131,3 +134,35 @@ bb0(%0 : $Bool):
131134
%rv = tuple ()
132135
return %rv : $()
133136
}
137+
138+
// CHECK-LABEL: sil shared [escapes %0 => %r] @$s21arg_escapes_to_return4main1XC_Tg5
139+
sil [escapes %1 => %0] @arg_escapes_to_return : $@convention(thin) <T> (@in_guaranteed T) -> @out T {
140+
bb0(%0 : $*T, %1 : $*T):
141+
copy_addr %1 to [initialization] %0 : $*T
142+
%4 = tuple ()
143+
return %4 : $()
144+
}
145+
146+
// CHECK-LABEL: sil shared [escapes %1 => %0] @$s015arg_escapes_to_A04main1XC_Tg5
147+
sil [escapes %1 => %0] @arg_escapes_to_arg : $@convention(thin) <T> (@inout T, @in_guaranteed T) -> () {
148+
bb0(%0 : $*T, %1 : $*T):
149+
copy_addr %1 to %0 : $*T
150+
%4 = tuple ()
151+
return %4 : $()
152+
}
153+
154+
sil @test_escape_effects : $@convention(thin) (@guaranteed X) -> @owned X {
155+
bb0(%0 : $X):
156+
%2 = alloc_stack $X
157+
%3 = alloc_stack $X
158+
store %0 to %3 : $*X
159+
%5 = function_ref @arg_escapes_to_return : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> @out τ_0_0
160+
%6 = apply %5<X>(%2, %3) : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> @out τ_0_0
161+
%7 = function_ref @arg_escapes_to_arg : $@convention(thin) <τ_0_0> (@inout τ_0_0, @in_guaranteed τ_0_0) -> ()
162+
%8 = apply %7<X>(%2, %3) : $@convention(thin) <τ_0_0> (@inout τ_0_0, @in_guaranteed τ_0_0) -> ()
163+
dealloc_stack %3 : $*X
164+
%10 = load %2 : $*X
165+
dealloc_stack %2 : $*X
166+
return %10 : $X
167+
}
168+

0 commit comments

Comments
 (0)