@@ -2403,7 +2403,7 @@ public func testSubscriptReadModify_BaseLoadable_ResultAddressOnly_InOut(m: inou
2403
2403
}
2404
2404
2405
2405
// CHECK-LABEL: sil [ossa] @$s8moveonly61testSubscriptReadModify_BaseLoadable_ResultAddressOnly_GlobalyyF : $@convention(thin) () -> () {
2406
- // CHECK: [[GLOBAL_ADDR:%.*]] = global_addr @$s8moveonly39globalLoadableSubscriptReadModifyTesterAA0cdefG0Vvp :
2406
+ // CHECK: [[GLOBAL_ADDR:%.*]] = global_addr @$s8moveonly39globalLoadableSubscriptReadModifyTesterAA0cdefG0Vvp :
2407
2407
//
2408
2408
// The get call
2409
2409
// CHECK: [[ACCESS:%.*]] = begin_access [read] [dynamic] [[GLOBAL_ADDR]]
@@ -3117,3 +3117,96 @@ public func testSubscriptGetModifyThroughParentClass_BaseLoadable_ResultAddressO
3117
3117
m. computedTester2 [ 0 ] . mutatingFunc ( )
3118
3118
}
3119
3119
3120
+ //////////////////////////////
3121
+ // MARK: Capture Self Tests //
3122
+ //////////////////////////////
3123
+
3124
+ func testSelfCaptureHandledCorrectly( ) {
3125
+ struct E {
3126
+ var a : [ Int ] = [ ]
3127
+ }
3128
+
3129
+ struct Test : ~ Copyable {
3130
+ var e : E
3131
+
3132
+ // Test that we capture inits by address.
3133
+ //
3134
+ // CHECK-LABEL: sil private [ossa] @$s8moveonly31testSelfCaptureHandledCorrectlyyyF4TestL_VADycfC : $@convention(method) (@thin Test.Type) -> @owned Test {
3135
+ // CHECK: [[BOX:%.*]] = alloc_box ${ var Test }
3136
+ // CHECK: [[MARK_UNINIT:%.*]] = mark_uninitialized [rootself] [[BOX]]
3137
+ // CHECK: [[BORROW:%.*]] = begin_borrow [lexical] [[MARK_UNINIT]]
3138
+ // CHECK: [[PROJECT:%.*]] = project_box [[BORROW]]
3139
+ // CHECK: apply {{%.*}}([[PROJECT]])
3140
+ // CHECK: } // end sil function '$s8moveonly31testSelfCaptureHandledCorrectlyyyF4TestL_VADycfC'
3141
+ init ( ) {
3142
+ e = E ( )
3143
+ func capture( ) {
3144
+ let e = self . e
3145
+ }
3146
+ capture ( )
3147
+ }
3148
+
3149
+ // CHECK-LABEL: sil private [ossa] @$s8moveonly31testSelfCaptureHandledCorrectlyyyF4TestL_V22captureByLocalFunctionyyF : $@convention(method) (@guaranteed Test) -> () {
3150
+ // CHECK: bb0([[ARG:%.*]] : @guaranteed $Test):
3151
+ // CHECK: [[COPY:%.*]] = copy_value [[ARG]]
3152
+ // CHECK: [[MARK:%.*]] = mark_must_check [no_consume_or_assign] [[COPY]]
3153
+ // CHECK: [[BORROW:%.*]] = begin_borrow [[MARK]]
3154
+ // CHECK: apply {{%.*}}([[BORROW]])
3155
+ // CHECK: end_borrow [[BORROW]]
3156
+ // CHECK: destroy_value [[MARK]]
3157
+ // CHECK: } // end sil function '$s8moveonly31testSelfCaptureHandledCorrectlyyyF4TestL_V22captureByLocalFunctionyyF'
3158
+ func captureByLocalFunction( ) {
3159
+ func capture( ) {
3160
+ let e = self . e
3161
+ }
3162
+ capture ( )
3163
+ }
3164
+
3165
+ // CHECK-LABEL: sil private [ossa] @$s8moveonly31testSelfCaptureHandledCorrectlyyyF4TestL_V17captureByLocalLetyyF : $@convention(method) (@guaranteed Test) -> () {
3166
+ // CHECK: bb0([[ARG:%.*]] : @guaranteed $Test):
3167
+ // CHECK: [[COPY:%.*]] = copy_value [[ARG]]
3168
+ // CHECK: [[MARK:%.*]] = mark_must_check [no_consume_or_assign] [[COPY]]
3169
+ // CHECK: [[COPY2:%.*]] = copy_value [[MARK]]
3170
+ // CHECK: [[PAI:%.*]] = partial_apply [callee_guaranteed] {{%.*}}([[COPY2]])
3171
+ // CHECK: destroy_value [[MARK]]
3172
+ // CHECK: } // end sil function '$s8moveonly31testSelfCaptureHandledCorrectlyyyF4TestL_V17captureByLocalLetyyF'
3173
+ func captureByLocalLet( ) {
3174
+ let f = {
3175
+ let e = self . e
3176
+ }
3177
+
3178
+ f ( )
3179
+ }
3180
+
3181
+ // CHECK-LABEL: sil private [ossa] @$s8moveonly31testSelfCaptureHandledCorrectlyyyF4TestL_V17captureByLocalVaryyF : $@convention(method) (@guaranteed Test) -> () {
3182
+ // CHECK: bb0([[ARG:%.*]] : @guaranteed $Test):
3183
+ // CHECK: [[COPY:%.*]] = copy_value [[ARG]]
3184
+ // CHECK: [[MARK:%.*]] = mark_must_check [no_consume_or_assign] [[COPY]]
3185
+ // CHECK: [[COPY2:%.*]] = copy_value [[MARK]]
3186
+ // CHECK: [[PAI:%.*]] = partial_apply [callee_guaranteed] {{%.*}}([[COPY2]])
3187
+ // CHECK: destroy_value [[MARK]]
3188
+ // CHECK: } // end sil function '$s8moveonly31testSelfCaptureHandledCorrectlyyyF4TestL_V17captureByLocalVaryyF'
3189
+ func captureByLocalVar( ) {
3190
+ var f = { }
3191
+ f = {
3192
+ let e = self . e
3193
+ }
3194
+ f ( )
3195
+ }
3196
+
3197
+ // CHECK-LABEL: sil private [ossa] @$s8moveonly31testSelfCaptureHandledCorrectlyyyF4TestL_V27captureByNonEscapingClosureyyF : $@convention(method) (@guaranteed Test) -> () {
3198
+ // CHECK: bb0([[ARG:%.*]] : @guaranteed $Test):
3199
+ // CHECK: [[COPY:%.*]] = copy_value [[ARG]]
3200
+ // CHECK: [[MARK:%.*]] = mark_must_check [no_consume_or_assign] [[COPY]]
3201
+ // CHECK: [[COPY2:%.*]] = copy_value [[MARK]]
3202
+ // CHECK: [[PAI:%.*]] = partial_apply [callee_guaranteed] {{%.*}}([[COPY2]])
3203
+ // CHECK: destroy_value [[MARK]]
3204
+ // CHECK: } // end sil function '$s8moveonly31testSelfCaptureHandledCorrectlyyyF4TestL_V27captureByNonEscapingClosureyyF'
3205
+ func captureByNonEscapingClosure( ) {
3206
+ func useClosure( _ f: ( ) -> ( ) ) { }
3207
+ useClosure {
3208
+ let e = self . e
3209
+ }
3210
+ }
3211
+ }
3212
+ }
0 commit comments