@@ -67,6 +67,26 @@ struct Holder {
67
67
@_addressableForDependencies
68
68
struct AddressableForDeps {}
69
69
70
+ public struct MutableView : ~Copyable, ~Escapable {
71
+ @_hasStorage var ptr: UnsafeMutableRawBufferPointer { get set }
72
+ init(ptr: UnsafeMutableRawBufferPointer)
73
+ }
74
+
75
+ public struct Container : ~Escapable, ~Copyable {
76
+ @_hasStorage var somethings: UnsafeMutableRawBufferPointer { get set }
77
+ init(somethings: UnsafeMutableRawBufferPointer)
78
+ }
79
+
80
+ public struct AThing : ~Copyable {
81
+ @_hasStorage var somethings: UnsafeMutableRawBufferPointer { get set }
82
+ init(somethings: UnsafeMutableRawBufferPointer)
83
+ }
84
+
85
+ sil @getContainer : $@convention(thin) (@inout AThing) -> @lifetime(borrow address_for_deps 0) @out Container
86
+ sil @getMutableView : $@convention(thin) (@in_guaranteed Container) -> @lifetime(copy 0) @out Optional<MutableView>
87
+ sil @modAThing : $@convention(thin) (@inout AThing) -> ()
88
+ sil @getSpan : $@convention(thin) (@inout MutableView) -> @lifetime(borrow address_for_deps 0) @owned MutableRawSpan
89
+
70
90
sil @getNEPointerToA : $@convention(thin) (@guaranteed NE) -> UnsafePointer<A>
71
91
sil @useA : $@convention(thin) (A) -> ()
72
92
@@ -678,3 +698,95 @@ bb2(%25 : @guaranteed $NCWrapper):
678
698
%37 = tuple ()
679
699
return %37
680
700
}
701
+
702
+ // rdar://151231236 ([~Escapable] Missing 'overlapping acceses' error when called from client code, but exact same code
703
+ // produces error in same module)
704
+ //
705
+ // Test access scope expansion over a switch_enum_addr
706
+ // CHECK-LABEL: sil hidden [ossa] @testSwitchEnumAddr : $@convention(thin) @async (@inout AThing) -> @error any Error {
707
+ // CHECK: bb0(%0 : $*AThing):
708
+ // CHECK: [[ATHING:%[0-9]+]] = mark_unresolved_non_copyable_value [consumable_and_assignable] %0
709
+ // CHECK: [[ACCESS:%[0-9]+]] = begin_access [modify] [unknown] [[ATHING]]
710
+ // CHECK: apply {{.*}}(%{{.*}}, [[ACCESS]]) : $@convention(thin) (@inout AThing) -> @lifetime(borrow address_for_deps 0) @out Container
711
+ // CHECK: mark_dependence_addr [unresolved] %{{.*}} on [[ACCESS]]
712
+ // CHECK: [[VIEW:%[0-9]+]] = project_box
713
+ // CHECK: [[TMP:%[0-9]+]] = alloc_stack $Optional<MutableView>
714
+ // CHECK: [[TMP_NC:%[0-9]+]] = mark_unresolved_non_copyable_value [consumable_and_assignable] [[TMP]]
715
+ // CHECK: apply %{{.*}} : $@convention(thin) (@in_guaranteed Container) -> @lifetime(copy 0) @out Optional<MutableView>
716
+ // CHECK: switch_enum_addr [[TMP_NC]], case #Optional.some!enumelt: bb2, case #Optional.none!enumelt: bb1
717
+ // CHECK: bb1:
718
+ // CHECK: bb2:
719
+ // CHECK: [[DATA:%[0-9]+]] = unchecked_take_enum_data_addr [[TMP_NC]], #Optional.some!enumelt
720
+ // CHECK: copy_addr [take] [[DATA]] to [init] [[VIEW]]
721
+ // CHECK: begin_access [modify] [unknown] [[ATHING]]
722
+ // CHECK: apply %{{.*}} : $@convention(thin) (@inout AThing) -> ()
723
+ // CHECK: [[ACCESS_VIEW:%[0-9]+]] = begin_access [modify] [unknown] [[VIEW]]
724
+ // CHECK: apply {{.*}} : $@convention(thin) (@inout MutableView) -> @lifetime(borrow address_for_deps 0) @owned MutableRawSpan
725
+ // CHECK: mark_dependence [unresolved]
726
+ // CHECK: end_access [[ACCESS_VIEW]]
727
+ // CHECK: end_access [[ACCESS]]
728
+ // CHECK: store
729
+ // CHECK-LABEL: } // end sil function 'testSwitchEnumAddr'
730
+ sil hidden [ossa] @testSwitchEnumAddr : $@convention(thin) @async (@inout AThing) -> @error any Error {
731
+ bb0(%0 : $*AThing):
732
+ %1 = mark_unresolved_non_copyable_value [consumable_and_assignable] %0
733
+ %2 = alloc_box ${ var Container }, var, name "container"
734
+ %3 = begin_borrow [lexical] [var_decl] %2
735
+ %4 = project_box %3, 0
736
+ %5 = begin_access [modify] [unknown] %1
737
+
738
+ %6 = function_ref @getContainer : $@convention(thin) (@inout AThing) -> @lifetime(borrow address_for_deps 0) @out Container
739
+ %7 = apply %6(%4, %5) : $@convention(thin) (@inout AThing) -> @lifetime(borrow address_for_deps 0) @out Container
740
+ mark_dependence_addr [unresolved] %4 on %5
741
+ end_access %5
742
+ %10 = alloc_box ${ var MutableView }, var, name "view"
743
+ %11 = begin_borrow [lexical] [var_decl] %10
744
+ %12 = project_box %11, 0
745
+
746
+ %13 = alloc_stack $Optional<MutableView>
747
+ %14 = mark_unresolved_non_copyable_value [consumable_and_assignable] %13
748
+ %15 = begin_access [read] [unknown] %4
749
+ %16 = mark_unresolved_non_copyable_value [no_consume_or_assign] %15
750
+
751
+ %17 = function_ref @getMutableView : $@convention(thin) (@in_guaranteed Container) -> @lifetime(copy 0) @out Optional<MutableView>
752
+ %18 = apply %17(%14, %16) : $@convention(thin) (@in_guaranteed Container) -> @lifetime(copy 0) @out Optional<MutableView>
753
+ end_access %15
754
+
755
+ switch_enum_addr %14, case #Optional.some!enumelt: bb2, case #Optional.none!enumelt: bb1
756
+
757
+ bb1:
758
+ end_borrow %11
759
+ dealloc_box [dead_end] %10
760
+ end_borrow %3
761
+ dealloc_box [dead_end] %2
762
+ unreachable
763
+
764
+ bb2:
765
+ %44 = unchecked_take_enum_data_addr %14, #Optional.some!enumelt
766
+ copy_addr [take] %44 to [init] %12
767
+ dealloc_stack %13
768
+
769
+ %22 = begin_access [modify] [unknown] %1
770
+ %23 = function_ref @modAThing : $@convention(thin) (@inout AThing) -> ()
771
+ %24 = apply %23(%22) : $@convention(thin) (@inout AThing) -> ()
772
+ end_access %22
773
+ %26 = alloc_box ${ var MutableRawSpan }, var, name "span"
774
+ %27 = begin_borrow [lexical] [var_decl] %26
775
+ %28 = project_box %27, 0
776
+ %29 = begin_access [modify] [unknown] %12
777
+ %30 = mark_unresolved_non_copyable_value [assignable_but_not_consumable] %29
778
+
779
+ %31 = function_ref @getSpan : $@convention(thin) (@inout MutableView) -> @lifetime(borrow address_for_deps 0) @owned MutableRawSpan
780
+ %32 = apply %31(%30) : $@convention(thin) (@inout MutableView) -> @lifetime(borrow address_for_deps 0) @owned MutableRawSpan
781
+ %33 = mark_dependence [unresolved] %32 on %30
782
+ end_access %29
783
+ store %33 to [init] %28
784
+ end_borrow %27
785
+ destroy_value %26
786
+ end_borrow %11
787
+ destroy_value %10
788
+ end_borrow %3
789
+ destroy_value %2
790
+ %42 = tuple ()
791
+ return %42
792
+ }
0 commit comments