@@ -31,6 +31,8 @@ sil @takeC : $@convention(thin) (@guaranteed C) -> ()
31
31
sil @takeOwnedC : $@convention(thin) (@owned C) -> ()
32
32
sil @takeS1 : $@convention(thin) (@guaranteed S1) -> ()
33
33
sil @takeS2 : $@convention(thin) (@guaranteed S2) -> ()
34
+ sil @simple_func : $@convention(thin) () -> ()
35
+ sil @use_closure : $@convention(thin) (@guaranteed @callee_guaranteed () -> ()) -> ()
34
36
35
37
// CHECK-LABEL: sil [ossa] @replace_simple :
36
38
// CHECK-NOT: begin_borrow
@@ -438,3 +440,43 @@ bb3:
438
440
%retval = tuple ()
439
441
return %retval : $()
440
442
}
443
+
444
+ // CHECK-LABEL: sil [ossa] @remove_borrow_of_thin_function :
445
+ // CHECK: %1 = thin_to_thick_function
446
+ // CHECK-NOT: begin_borrow
447
+ // CHECK: %3 = apply %2(%1)
448
+ // CHECK: %4 = apply %1()
449
+ // CHECK-LABEL: } // end sil function 'remove_borrow_of_thin_function'
450
+ sil [ossa] @remove_borrow_of_thin_function : $@convention(thin) () -> () {
451
+ bb0:
452
+ %0 = function_ref @simple_func : $@convention(thin) () -> ()
453
+ %1 = thin_to_thick_function %0 to $@callee_guaranteed () -> ()
454
+ %2 = begin_borrow %1
455
+ %3 = function_ref @use_closure : $@convention(thin) (@guaranteed @callee_guaranteed () -> ()) -> ()
456
+ %4 = apply %3(%2) : $@convention(thin) (@guaranteed @callee_guaranteed () -> ()) -> ()
457
+ %5 = apply %2(): $@callee_guaranteed () -> ()
458
+ end_borrow %2
459
+ %r = tuple ()
460
+ return %r
461
+ }
462
+
463
+ // CHECK-LABEL: sil [ossa] @dont_remove_borrow_of_thin_function :
464
+ // CHECK: thin_to_thick_function
465
+ // CHECK-NEXT: begin_borrow
466
+ // CHECK-LABEL: } // end sil function 'dont_remove_borrow_of_thin_function'
467
+ sil [ossa] @dont_remove_borrow_of_thin_function : $@convention(thin) () -> () {
468
+ bb0:
469
+ %0 = function_ref @simple_func : $@convention(thin) () -> ()
470
+ %1 = thin_to_thick_function %0 to $@callee_guaranteed () -> ()
471
+ %2 = begin_borrow %1
472
+ %3 = function_ref @use_closure : $@convention(thin) (@guaranteed @callee_guaranteed () -> ()) -> ()
473
+ %4 = apply %3(%2) : $@convention(thin) (@guaranteed @callee_guaranteed () -> ()) -> ()
474
+ %5 = apply %2(): $@callee_guaranteed () -> ()
475
+ br bb1(%2)
476
+ bb1(%7 : @reborrow $@callee_guaranteed () -> ()):
477
+ %8 = borrowed %7 from ()
478
+ end_borrow %8
479
+ %r = tuple ()
480
+ return %r
481
+ }
482
+
0 commit comments