@@ -499,3 +499,36 @@ bb0(%0 : $Array<Int>):
499
499
%25 = tuple ()
500
500
return %25 : $()
501
501
}
502
+
503
+ struct InGuaranteedArgTestNativeObjectWrapper {
504
+ var i: Builtin.NativeObject
505
+ }
506
+
507
+ protocol InGuaranteedArgTestProtocol {}
508
+ extension InGuaranteedArgTestNativeObjectWrapper : InGuaranteedArgTestProtocol {}
509
+
510
+ sil @in_guaranteed_arg_test_callee : $@convention(thin) <τ_0_0 where τ_0_0 : InGuaranteedArgTestProtocol> (@in τ_0_0) -> ()
511
+
512
+ // The current transformation is not smart enough to remove the
513
+ // destroy_addr. Simply substituting the copy source for the apply argument
514
+ // would introduce a use-after-free. = (.
515
+ //
516
+ // CHECK-LABEL: sil @in_guaranteed_arg_test_caller : $@convention(thin) <τ_0_0 where τ_0_0 : InGuaranteedArgTestProtocol> (@in τ_0_0) -> () {
517
+ // CHECK: apply {{%.*}}<@opened("C494A60E-71EA-11E9-B8C0-D0817AD3F8AD") InGuaranteedArgTestProtocol>
518
+ // CHECK: } // end sil function 'in_guaranteed_arg_test_caller'
519
+ sil @in_guaranteed_arg_test_caller : $@convention(thin) <τ_0_0 where τ_0_0 : InGuaranteedArgTestProtocol> (@in τ_0_0) -> () {
520
+ bb0(%0 : $*τ_0_0):
521
+ %1 = alloc_stack $InGuaranteedArgTestProtocol
522
+ %2 = init_existential_addr %1 : $*InGuaranteedArgTestProtocol, $τ_0_0
523
+ copy_addr [take] %0 to [initialization] %2 : $*τ_0_0
524
+ %3 = function_ref @in_guaranteed_arg_test_callee : $@convention(thin) <τ_0_0 where τ_0_0 : InGuaranteedArgTestProtocol> (@in τ_0_0) -> ()
525
+ %4 = alloc_stack $InGuaranteedArgTestProtocol
526
+ copy_addr %1 to [initialization] %4 : $*InGuaranteedArgTestProtocol
527
+ %5 = open_existential_addr mutable_access %4 : $*InGuaranteedArgTestProtocol to $*@opened("C494A60E-71EA-11E9-B8C0-D0817AD3F8AD") InGuaranteedArgTestProtocol
528
+ apply %3<@opened("C494A60E-71EA-11E9-B8C0-D0817AD3F8AD") InGuaranteedArgTestProtocol>(%5) : $@convention(thin) <τ_0_0 where τ_0_0 : InGuaranteedArgTestProtocol> (@in τ_0_0) -> ()
529
+ dealloc_stack %4 : $*InGuaranteedArgTestProtocol
530
+ destroy_addr %1 : $*InGuaranteedArgTestProtocol
531
+ dealloc_stack %1 : $*InGuaranteedArgTestProtocol
532
+ %9999 = tuple()
533
+ return %9999 : $()
534
+ }
0 commit comments