@@ -332,3 +332,53 @@ bb0(%0: @trivial $*Int, %1 : @owned $<τ_0_0> { var τ_0_0 } <Foo>, %2 : @owned
332
332
%16 = tuple()
333
333
return %16 : $()
334
334
}
335
+
336
+ // This test makes sure that we properly handle non load uses of
337
+ // struct_element_addr that always have load users with the load occuring before
338
+ // and after the element in the use list.
339
+
340
+ sil @mutate_int : $@convention(thin) (@inout Int) -> ()
341
+
342
+ // CHECK-LABEL: sil @test_closure_multiple_uses_of_struct_element_addr : $@convention(thin) () -> @owned @callee_owned () -> () {
343
+ // CHECK: [[FUNC:%.*]] = function_ref @closure_multiple_uses_of_struct_element_addr : $@convention(thin)
344
+ // CHECK: partial_apply [[FUNC]](
345
+ // CHECK: } // end sil function 'test_closure_multiple_uses_of_struct_element_addr'
346
+ sil @test_closure_multiple_uses_of_struct_element_addr : $@convention(thin) () -> @owned @callee_owned () -> () {
347
+ bb0:
348
+ %0 = function_ref @baz_init : $@convention(thin) (@thin Baz.Type) -> @owned Baz
349
+ %1 = metatype $@thin Baz.Type
350
+
351
+ %2 = alloc_box $<τ_0_0> { var τ_0_0 } <Baz>
352
+ %3 = project_box %2 : $<τ_0_0> { var τ_0_0 } <Baz>, 0
353
+ %4 = apply %0(%1) : $@convention(thin) (@thin Baz.Type) -> @owned Baz
354
+ store %4 to [init] %3 : $*Baz
355
+
356
+ %5 = alloc_box $<τ_0_0> { var τ_0_0 } <Baz>
357
+ %6 = project_box %5 : $<τ_0_0> { var τ_0_0 } <Baz>, 0
358
+ %7 = apply %0(%1) : $@convention(thin) (@thin Baz.Type) -> @owned Baz
359
+ store %7 to [init] %6 : $*Baz
360
+
361
+ %8 = function_ref @closure_multiple_uses_of_struct_element_addr : $@convention(thin) (@owned <τ_0_0> { var τ_0_0 } <Baz>, @owned <τ_0_0> { var τ_0_0 } <Baz>) -> ()
362
+ %9 = partial_apply %8(%2, %5) : $@convention(thin) (@owned <τ_0_0> { var τ_0_0 } <Baz>, @owned <τ_0_0> { var τ_0_0 } <Baz>) -> ()
363
+
364
+ return %9 : $@callee_owned () -> ()
365
+ }
366
+
367
+ sil @closure_multiple_uses_of_struct_element_addr : $@convention(thin) (@owned <τ_0_0> { var τ_0_0 } <Baz>, @owned <τ_0_0> { var τ_0_0 } <Baz>) -> () {
368
+ bb0(%0 : @owned $<τ_0_0> { var τ_0_0 } <Baz>, %1 : @owned $<τ_0_0> { var τ_0_0 } <Baz>):
369
+ %2 = project_box %0 : $<τ_0_0> { var τ_0_0 } <Baz>, 0
370
+ %3 = struct_element_addr %2 : $*Baz, #Baz.x
371
+ %4 = load [trivial] %3 : $*Int
372
+ %5 = function_ref @mutate_int : $@convention(thin) (@inout Int) -> ()
373
+ apply %5(%3) : $@convention(thin) (@inout Int) -> ()
374
+
375
+ %6 = project_box %1 : $<τ_0_0> { var τ_0_0 } <Baz>, 0
376
+ %7 = struct_element_addr %6 : $*Baz, #Baz.x
377
+ apply %5(%7) : $@convention(thin) (@inout Int) -> ()
378
+ %8 = load [trivial] %7 : $*Int
379
+
380
+ destroy_value %1 : $<τ_0_0> { var τ_0_0 } <Baz>
381
+ destroy_value %0 : $<τ_0_0> { var τ_0_0 } <Baz>
382
+ %9999 = tuple()
383
+ return %9999 : $()
384
+ }
0 commit comments