@@ -9,6 +9,10 @@ import Builtin
9
9
//////////////////
10
10
11
11
enum MyNever {}
12
+ enum FakeOptional<T> {
13
+ case none
14
+ case some(T)
15
+ }
12
16
13
17
sil @guaranteed_user : $@convention(thin) (@guaranteed Builtin.NativeObject) -> ()
14
18
sil @owned_user : $@convention(thin) (@owned Builtin.NativeObject) -> ()
@@ -24,6 +28,7 @@ sil @get_nativeobject_pair : $@convention(thin) () -> @owned NativeObjectPair
24
28
25
29
class Klass {}
26
30
sil @guaranteed_klass_user : $@convention(thin) (@guaranteed Klass) -> ()
31
+ sil @guaranteed_fakeoptional_klass_user : $@convention(thin) (@guaranteed FakeOptional<Klass>) -> ()
27
32
28
33
struct MyInt {
29
34
var value: Builtin.Int32
@@ -40,11 +45,6 @@ struct StructMemberTest {
40
45
var t : (Builtin.Int32, AnotherStruct)
41
46
}
42
47
43
- enum FakeOptional<T> {
44
- case none
45
- case some(T)
46
- }
47
-
48
48
class ClassLet {
49
49
@_hasStorage let aLet: Klass
50
50
@_hasStorage var aVar: Klass
@@ -589,6 +589,52 @@ bb0(%x : @owned $ClassLet):
589
589
return undef : $()
590
590
}
591
591
592
+ // We do not support this today, but we will once forwarding is ignored when
593
+ // checking if the load [copy] is a dead live range.
594
+ //
595
+ // CHECK-LABEL: sil [ossa] @dont_copy_let_properties_with_borrowed_base_that_dominates_projtestcase :
596
+ // CHECK: load [copy]
597
+ // CHECK: } // end sil function 'dont_copy_let_properties_with_borrowed_base_that_dominates_projtestcase'
598
+ sil [ossa] @dont_copy_let_properties_with_borrowed_base_that_dominates_projtestcase : $@convention(thin) (@owned ClassLet) -> () {
599
+ bb0(%x : @owned $ClassLet):
600
+ %f = function_ref @black_hole : $@convention(thin) (@guaranteed Klass) -> ()
601
+
602
+ %a = begin_borrow %x : $ClassLet
603
+ %p = ref_element_addr %a : $ClassLet, #ClassLet.aLetTuple
604
+ %v = load [copy] %p : $*(Klass, Klass)
605
+ (%v1, %v2) = destructure_tuple %v : $(Klass, Klass)
606
+ apply %f(%v1) : $@convention(thin) (@guaranteed Klass) -> ()
607
+ apply %f(%v2) : $@convention(thin) (@guaranteed Klass) -> ()
608
+ destroy_value %v1 : $Klass
609
+ destroy_value %v2 : $Klass
610
+ end_borrow %a : $ClassLet
611
+ destroy_value %x : $ClassLet
612
+
613
+ return undef : $()
614
+ }
615
+
616
+ // We do not support this today, but we will once forwarding is ignored when
617
+ // checking if the load [copy] is a dead live range.
618
+ //
619
+ // CHECK-LABEL: sil [ossa] @dont_copy_let_properties_with_borrowed_base_that_dominates_projtestcase_2 :
620
+ // CHECK: load [copy]
621
+ // CHECK: } // end sil function 'dont_copy_let_properties_with_borrowed_base_that_dominates_projtestcase_2'
622
+ sil [ossa] @dont_copy_let_properties_with_borrowed_base_that_dominates_projtestcase_2 : $@convention(thin) (@owned ClassLet) -> () {
623
+ bb0(%x : @owned $ClassLet):
624
+ %f = function_ref @guaranteed_user : $@convention(thin) (@guaranteed Builtin.NativeObject) -> ()
625
+
626
+ %a = begin_borrow %x : $ClassLet
627
+ %p = ref_element_addr %a : $ClassLet, #ClassLet.aLet
628
+ %v = load [copy] %p : $*Klass
629
+ %v_cast = unchecked_ref_cast %v : $Klass to $Builtin.NativeObject
630
+ apply %f(%v_cast) : $@convention(thin) (@guaranteed Builtin.NativeObject) -> ()
631
+ destroy_value %v_cast : $Builtin.NativeObject
632
+ end_borrow %a : $ClassLet
633
+ destroy_value %x : $ClassLet
634
+
635
+ return undef : $()
636
+ }
637
+
592
638
// CHECK-LABEL: sil [ossa] @dont_copy_let_properties_with_multi_borrowed_base_that_dominates
593
639
// CHECK: [[OUTER:%.*]] = begin_borrow
594
640
// CHECK-NEXT: ref_element_addr
@@ -662,7 +708,7 @@ bb0(%x : @owned $ClassLet):
662
708
return undef : $()
663
709
}
664
710
665
- // CHECK-LABEL: sil [ossa] @do_or_dont_copy_let_properties_with_multi_borrowed_base_when_it_dominates
711
+ // CHECK-LABEL: sil [ossa] @do_or_dont_copy_let_properties_with_multi_borrowed_base_when_it_dominates_2 :
666
712
// CHECK: [[OUTER:%.*]] = begin_borrow
667
713
// CHECK-NEXT: ref_element_addr
668
714
// CHECK-NEXT: [[INNER:%.*]] = load_borrow
@@ -672,12 +718,15 @@ bb0(%x : @owned $ClassLet):
672
718
// CHECK-NEXT: begin_borrow
673
719
// CHECK-NEXT: ref_element_addr
674
720
// CHECK-NEXT: load [copy]
675
- // CHECK-NEXT: apply
676
721
// CHECK-NEXT: end_borrow
677
722
// CHECK-NEXT: destroy_value
723
+ // CHECK-NEXT: // function_ref
724
+ // CHECK-NEXT: function_ref
725
+ // CHECK-NEXT: enum
678
726
// CHECK-NEXT: apply
679
727
// CHECK-NEXT: destroy_value
680
- sil [ossa] @do_or_dont_copy_let_properties_with_multi_borrowed_base_when_it_dominates : $@convention(thin) (@owned ClassLet) -> () {
728
+ // CHECK: } // end sil function 'do_or_dont_copy_let_properties_with_multi_borrowed_base_when_it_dominates_2'
729
+ sil [ossa] @do_or_dont_copy_let_properties_with_multi_borrowed_base_when_it_dominates_2 : $@convention(thin) (@owned ClassLet) -> () {
681
730
bb0(%x : @owned $ClassLet):
682
731
%f = function_ref @black_hole : $@convention(thin) (@guaranteed Klass) -> ()
683
732
@@ -693,18 +742,17 @@ bb0(%x : @owned $ClassLet):
693
742
%b = begin_borrow %x : $ClassLet
694
743
%q = ref_element_addr %b : $ClassLet, #ClassLet.aLet
695
744
%w = load [copy] %q : $*Klass
696
- %d = begin_borrow %w : $Klass
697
- apply %f(%d) : $@convention(thin) (@guaranteed Klass) -> ()
698
745
699
746
// End the lifetime of the base object first...
700
747
end_borrow %b : $ClassLet
701
748
destroy_value %x : $ClassLet
702
749
703
750
// ...then end the lifetime of the copy.
704
- apply %f(%d) : $@convention(thin) (@guaranteed Klass) -> ()
751
+ %f2 = function_ref @guaranteed_fakeoptional_klass_user : $@convention(thin) (@guaranteed FakeOptional<Klass>) -> ()
752
+ %w2 = enum $FakeOptional<Klass>, #FakeOptional.some!enumelt.1, %w : $Klass
753
+ apply %f2(%w2) : $@convention(thin) (@guaranteed FakeOptional<Klass>) -> ()
705
754
706
- end_borrow %d : $Klass
707
- destroy_value %w : $Klass
755
+ destroy_value %w2 : $FakeOptional<Klass>
708
756
709
757
return undef : $()
710
758
}
0 commit comments