File: moveonly_addresschecker_maximize.sil

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (1130 lines) | stat: -rw-r--r-- 52,758 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
// RUN: %target-sil-opt -sil-move-only-address-checker -enable-sil-verify-all %s | %FileCheck %s
sil_stage raw

import Builtin

// #############################################################################
// #############################################################################
// SCALAR STORAGE                                                             {{
// #############################################################################
// #############################################################################

sil [ossa] @condition : $@convention(thin) () -> Builtin.Int1

@_moveOnly struct S {
  deinit
}

sil [ossa] @get : $@convention(thin) () -> @out S
sil [ossa] @get_value : $@convention(thin) () -> @owned S

sil [ossa] @see : $@convention(thin) (@guaranteed S) -> ()
sil [ossa] @see_addr : $@convention(thin) (@in_guaranteed S) -> ()

sil [ossa] @end : $@convention(thin) (@owned S) -> ()
sil [ossa] @end_addr : $@convention(thin) (@in S) -> ()

sil [ossa] @other : $@convention(thin) () -> ()

// =============================================================================
// =============================================================================
// Single def                                                                 {{
// =============================================================================
// =============================================================================

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Single block                                                               {{
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// A load-copy of the value is passed to a value-consuming function, and the
// storage is destroyed at function end.
//
// Ensure that there is no copy and the lifetime ends at the value-consume.
// CHECK-LABEL: sil [ossa] @singleblock_consume_value_before_other : {{.*}} {
// CHECK:         [[OTHER:%[^,]+]] = function_ref @other
// CHECK:         [[GET_VALUE:%[^,]+]] = function_ref @get_value
// CHECK:         [[END:%[^,]+]] = function_ref @end
// CHECK:         [[STACK:%[^,]+]] = alloc_stack
// CHECK:         [[INSTANCE:%[^,]+]] = apply [[GET_VALUE]]()
// CHECK:         store [[INSTANCE]] to [init] [[STACK]]
// CHECK:         [[ACCESS:%[^,]+]] = begin_access [modify] [static] [[STACK]]
// CHECK:         [[INSTANCE_RELOAD:%[^,]+]] = load [take] [[ACCESS]]
// CHECK:         apply [[END]]([[INSTANCE_RELOAD]])
// CHECK:         end_access [[ACCESS]]
// CHECK:         apply [[OTHER]]()
// CHECK:         dealloc_stack [[STACK]]
// CHECK-LABEL: } // end sil function 'singleblock_consume_value_before_other'
sil [ossa] @singleblock_consume_value_before_other : $@convention(thin) () -> () {
bb0:
  %other = function_ref @other : $@convention(thin) () -> ()
  %get_value = function_ref @get_value : $@convention(thin) () -> @owned S
  %end = function_ref @end : $@convention(thin) (@owned S) -> ()

  %stack_addr = alloc_stack $S
  %stack = mark_unresolved_non_copyable_value [consumable_and_assignable] %stack_addr : $*S
  %instance = apply %get_value() : $@convention(thin) () -> @owned S
  store %instance to [init] %stack : $*S
  %access = begin_access [deinit] [static] %stack : $*S
  %instance_reload = load [copy] %access : $*S
  apply %end(%instance_reload) : $@convention(thin) (@owned S) -> ()
  end_access %access : $*S
  %18 = apply %other() : $@convention(thin) () -> ()
  destroy_addr %stack : $*S
  dealloc_stack %stack_addr : $*S
  %retval = tuple ()
  return %retval : $()
}

// A load-copy of the value is passed to a value-borrowing function then
// destroyed, and the storage is destroyed at function end.
//
// Ensure that there is no copy and the lifetime ends at function end.
// CHECK-LABEL: sil [ossa] @singleblock_borrow_before_other : {{.*}} {
// CHECK:         [[OTHER:%[^,]+]] = function_ref @other
// CHECK:         [[GET_VALUE:%[^,]+]] = function_ref @get_value
// CHECK:         [[SEE:%[^,]+]] = function_ref @see
// CHECK:         [[STACK:%[^,]+]] = alloc_stack
// CHECK:         [[INSTANCE:%[^,]+]] = apply [[GET_VALUE]]()
// CHECK:         store [[INSTANCE]] to [init] [[STACK]]
// CHECK:         [[ACCESS:%[^,]+]] = begin_access [deinit] [static] [[STACK]]
// CHECK:         [[BORROW:%[^,]+]] = load_borrow [[ACCESS]]
// CHECK:         apply [[SEE]]([[BORROW]])
// CHECK:         end_borrow [[BORROW]]
// CHECK:         end_access [[ACCESS]]
// CHECK:         apply [[OTHER]]()
// CHECK:         destroy_addr [[STACK]]
// CHECK:         dealloc_stack [[STACK]]
// CHECK-LABEL: } // end sil function 'singleblock_borrow_before_other'
sil [ossa] @singleblock_borrow_before_other : $@convention(thin) () -> () {
bb0:
  %other = function_ref @other : $@convention(thin) () -> ()
  %get_value = function_ref @get_value : $@convention(thin) () -> @owned S
  %see = function_ref @see : $@convention(thin) (@guaranteed S) -> ()
  %end = function_ref @end : $@convention(thin) (@owned S) -> ()

  %stack_addr = alloc_stack $S
  %stack = mark_unresolved_non_copyable_value [consumable_and_assignable] %stack_addr : $*S
  %instance = apply %get_value() : $@convention(thin) () -> @owned S
  store %instance to [init] %stack : $*S
  %access = begin_access [deinit] [static] %stack : $*S
  %instance_reload = load [copy] %access : $*S
  apply %see(%instance_reload) : $@convention(thin) (@guaranteed S) -> ()
  destroy_value %instance_reload : $S
  end_access %access : $*S
  %18 = apply %other() : $@convention(thin) () -> ()
  destroy_addr %stack : $*S
  dealloc_stack %stack_addr : $*S
  %retval = tuple ()
  return %retval : $()
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// }} Single block
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Multiple blocks                                                            {{
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// There is a consuming use in right.  So bottom is a consumed block.  Liveness
// is retracted up to the consume in right and up to the bottom of left.
// CHECK-LABEL: sil [ossa] @diamond__consume_r__use_l__destroy_b : {{.*}} {
// CHECK:         [[STACK:%[^,]+]] = alloc_stack
// CHECK:         [[GET:%[^,]+]] = function_ref @get
// CHECK:         [[OTHER:%[^,]+]] = function_ref @other
// CHECK:         [[SEE_ADDR:%[^,]+]] = function_ref @see_addr
// CHECK:         [[END:%[^,]+]] = function_ref @end
// CHECK:         apply [[GET]]([[STACK]])
// CHECK:         cond_br undef, [[LEFT:bb[0-9]+]], [[RIGHT:bb[0-9]+]]                         
// CHECK:       [[LEFT:bb[0-9]+]]:                                              
// CHECK:         apply [[SEE_ADDR]]([[STACK]])
// CHECK:         apply [[OTHER]]()
// CHECK:         destroy_addr [[STACK]]
// CHECK:         br [[BOTTOM:bb[0-9]+]]                                          
// CHECK:       [[RIGHT:bb[0-9]+]]:                                              
// CHECK:         [[INSTANCE:%[^,]+]] = load [take] [[STACK]]
// CHECK:         apply [[END]]([[INSTANCE]])
// CHECK:         br [[BOTTOM]]                                          
// CHECK:       [[BOTTOM]]:                                              
// CHECK-LABEL: } // end sil function 'diamond__consume_r__use_l__destroy_b'
sil [ossa] @diamond__consume_r__use_l__destroy_b : $@convention(thin) () -> () {
top:
    %stack_addr = alloc_stack $S
    %stack = mark_unresolved_non_copyable_value [consumable_and_assignable] %stack_addr : $*S
    %get = function_ref @get : $@convention(thin) () -> @out S
    %other = function_ref @other : $@convention(thin) () -> ()
    %see = function_ref @see : $@convention(thin) (@guaranteed S) -> ()
    %see_addr = function_ref @see_addr : $@convention(thin) (@in_guaranteed S) -> ()
    %end = function_ref @end : $@convention(thin) (@owned S) -> ()
    %end_addr = function_ref @end_addr : $@convention(thin) (@in S) -> ()
    apply %get(%stack) : $@convention(thin) () -> @out S
    cond_br undef, left, right
left:
    apply %see_addr(%stack) : $@convention(thin) (@in_guaranteed S) -> ()
    apply %other() : $@convention(thin) () -> ()
    br bottom
right:
    %copy = load [copy] %stack : $*S
    apply %end(%copy) : $@convention(thin) (@owned S) -> ()
    br bottom
bottom:
    destroy_addr %stack : $*S
    dealloc_stack %stack_addr : $*S
    %retval = tuple ()
    return %retval : $()
}

// Only bottom is consumedAtEntry.
// CHECK-LABEL: sil [ossa] @diamond_2r__consume_r1r2__use_l__destroy_b : {{.*}} {
// CHECK:         [[STACK:%[^,]+]] = alloc_stack
// CHECK:         [[GET:%[^,]+]] = function_ref @get
// CHECK:         [[SEE:%[^,]+]] = function_ref @see
// CHECK:         [[END:%[^,]+]] = function_ref @end
// CHECK:         apply [[GET]]([[STACK]])
// CHECK:         cond_br undef, [[LEFT:bb[0-9]+]], [[RIGHT:bb[0-9]+]]
// CHECK:       [[LEFT]]:
// CHECK:         [[BORROW:%[^,]+]] = load_borrow [[STACK]]
// CHECK:         apply [[SEE]]([[BORROW]])
// CHECK:         end_borrow [[BORROW]]
// CHECK:         destroy_addr [[STACK]]
// CHECK:         br [[BOTTOM:bb[0-9]+]]
// CHECK:       [[RIGHT]]:
// CHECK:         [[BORROW_2:%[^,]+]] = load_borrow [[STACK]]
// CHECK:         apply [[SEE]]([[BORROW_2]])
// CHECK:         end_borrow [[BORROW_2]]
// CHECK:         br [[RIGHT_2:bb[0-9]+]]
// CHECK:       [[RIGHT_2]]:
// CHECK:         [[TAKE:%[^,]+]] = load [take] [[STACK]]
// CHECK:         apply [[END]]([[TAKE]])
// CHECK:         br [[BOTTOM]]
// CHECK:       [[BOTTOM]]:
// CHECK-LABEL: } // end sil function 'diamond_2r__consume_r1r2__use_l__destroy_b'
sil [ossa] @diamond_2r__consume_r1r2__use_l__destroy_b : $@convention(thin) () -> () {
top:
    %stack_addr = alloc_stack $S
    %stack = mark_unresolved_non_copyable_value [consumable_and_assignable] %stack_addr : $*S
    %get = function_ref @get : $@convention(thin) () -> @out S
    %other = function_ref @other : $@convention(thin) () -> ()
    %see = function_ref @see : $@convention(thin) (@guaranteed S) -> ()
    %see_addr = function_ref @see_addr : $@convention(thin) (@in_guaranteed S) -> ()
    %end = function_ref @end : $@convention(thin) (@owned S) -> ()
    %end_addr = function_ref @end_addr : $@convention(thin) (@in S) -> ()
    apply %get(%stack) : $@convention(thin) () -> @out S
    cond_br undef, left, right
left:
    %copy3 = load [copy] %stack : $*S
    apply %see(%copy3) : $@convention(thin) (@guaranteed S) -> ()
    destroy_value %copy3 : $S
    br bottom
right:
    %copy = load [copy] %stack : $*S
    apply %see(%copy) : $@convention(thin) (@guaranteed S) -> ()
    destroy_value %copy : $S
    br right2
right2:
    %copy2 = load [copy] %stack : $*S
    apply %end(%copy2) : $@convention(thin) (@owned S) -> ()
    br bottom
bottom:
    destroy_addr %stack : $*S
    dealloc_stack %stack_addr : $*S
    %retval = tuple ()
    return %retval : $()
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// }} Multiple blocks
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// =============================================================================
// =============================================================================
// }} Single def
// =============================================================================
// =============================================================================

// =============================================================================
// =============================================================================
// Multiple defs                                                              {{
// =============================================================================
// =============================================================================

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Multiple blocks                                                            {{
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// Like diamond__consume_r__use_l__destroy_b but with a copy_addr [take] reinit
// in left.  The reinit is after an apply of other.
//
// Ensure that the destroy from that deinit remains at the same location--it
// will be split into a separate instruction.
//
// TODO: Avoid the unnecessary churn of that splitting.
// CHECK-LABEL: sil [ossa] @diamond__consume_r__reinit_l__use_l__destroy_b : {{.*}} {
// CHECK:         [[STACK:%[^,]+]] = alloc_stack
// CHECK:         [[GET:%[^,]+]] = function_ref @get
// CHECK:         [[OTHER:%[^,]+]] = function_ref @other
// CHECK:         [[SEE_ADDR:%[^,]+]] = function_ref @see_addr
// CHECK:         [[END:%[^,]+]] = function_ref @end
// CHECK:         apply [[GET]]([[STACK]])
// CHECK:         cond_br undef, [[LEFT:bb[0-9]+]], [[RIGHT:bb[0-9]+]]                         
// CHECK:       [[LEFT:bb[0-9]+]]:                                              
// CHECK:         apply [[OTHER]]()
// CHECK:         destroy_addr [[STACK]]
// CHECK:         apply [[SEE_ADDR]]([[STACK]])
// CHECK:         apply [[OTHER]]()
// CHECK:         destroy_addr [[STACK]]
// CHECK:         br [[BOTTOM:bb[0-9]+]]                                          
// CHECK:       [[RIGHT:bb[0-9]+]]:                                              
// CHECK:         [[INSTANCE:%[^,]+]] = load [take] [[STACK]]
// CHECK:         apply [[END]]([[INSTANCE]])
// CHECK:         br [[BOTTOM]]                                          
// CHECK:       [[BOTTOM]]:                                              
// CHECK-LABEL: } // end sil function 'diamond__consume_r__reinit_l__use_l__destroy_b'
sil [ossa] @diamond__consume_r__reinit_l__use_l__destroy_b : $@convention(thin) () -> () {
top:
    %stack_addr = alloc_stack $S
    %stack = mark_unresolved_non_copyable_value [consumable_and_assignable] %stack_addr : $*S
    %get = function_ref @get : $@convention(thin) () -> @out S
    %other = function_ref @other : $@convention(thin) () -> ()
    %see = function_ref @see : $@convention(thin) (@guaranteed S) -> ()
    %see_addr = function_ref @see_addr : $@convention(thin) (@in_guaranteed S) -> ()
    %end = function_ref @end : $@convention(thin) (@owned S) -> ()
    %end_addr = function_ref @end_addr : $@convention(thin) (@in S) -> ()
    apply %get(%stack) : $@convention(thin) () -> @out S
    cond_br undef, left, right
left:
    apply %other() : $@convention(thin) () -> ()
    %stack2 = alloc_stack $S
    apply %get(%stack2) : $@convention(thin) () -> @out S
    copy_addr [take] %stack2 to %stack : $*S
    dealloc_stack %stack2 : $*S
    apply %see_addr(%stack) : $@convention(thin) (@in_guaranteed S) -> ()
    apply %other() : $@convention(thin) () -> ()
    br bottom
right:
    %copy = load [copy] %stack : $*S
    apply %end(%copy) : $@convention(thin) (@owned S) -> ()
    br bottom
bottom:
    destroy_addr %stack : $*S
    dealloc_stack %stack_addr : $*S
    %retval = tuple ()
    return %retval : $()
}

// Like diamond__consume_r__reinit_l__use_l__destroy_b with a store [assign]
// reinit in left.  The reinit is after an apply of other.
//
// Ensure that the destroy from that deinit remains at the same location--it
// will be split into a separate instruction.
//
// TODO: Avoid the unnecessary churn of that splitting.
// CHECK-LABEL: sil [ossa] @diamond__consume_r__reinit_l__use_l__destroy_b2 : {{.*}} {
// CHECK:         [[STACK:%[^,]+]] = alloc_stack
// CHECK:         [[GET:%[^,]+]] = function_ref @get
// CHECK:         [[OTHER:%[^,]+]] = function_ref @other
// CHECK:         [[SEE_ADDR:%[^,]+]] = function_ref @see_addr
// CHECK:         [[END:%[^,]+]] = function_ref @end
// CHECK:         apply [[GET]]([[STACK]])
// CHECK:         cond_br undef, [[LEFT:bb[0-9]+]], [[RIGHT:bb[0-9]+]]                         
// CHECK:       [[LEFT:bb[0-9]+]]:                                              
// CHECK:         apply [[OTHER]]()
// CHECK:         destroy_addr [[STACK]]
// CHECK:         apply [[SEE_ADDR]]([[STACK]])
// CHECK:         apply [[OTHER]]()
// CHECK:         destroy_addr [[STACK]]
// CHECK:         br [[BOTTOM:bb[0-9]+]]                                          
// CHECK:       [[RIGHT:bb[0-9]+]]:                                              
// CHECK:         [[INSTANCE:%[^,]+]] = load [take] [[STACK]]
// CHECK:         apply [[END]]([[INSTANCE]])
// CHECK:         br [[BOTTOM]]                                          
// CHECK:       [[BOTTOM]]:                                              
// CHECK-LABEL: } // end sil function 'diamond__consume_r__reinit_l__use_l__destroy_b2'
sil [ossa] @diamond__consume_r__reinit_l__use_l__destroy_b2 : $@convention(thin) () -> () {
top:
    %stack_addr = alloc_stack $S
    %stack = mark_unresolved_non_copyable_value [consumable_and_assignable] %stack_addr : $*S
    %get = function_ref @get : $@convention(thin) () -> @out S
    %get_value = function_ref @get_value : $@convention(thin) () -> @owned S
    %other = function_ref @other : $@convention(thin) () -> ()
    %see = function_ref @see : $@convention(thin) (@guaranteed S) -> ()
    %see_addr = function_ref @see_addr : $@convention(thin) (@in_guaranteed S) -> ()
    %end = function_ref @end : $@convention(thin) (@owned S) -> ()
    %end_addr = function_ref @end_addr : $@convention(thin) (@in S) -> ()
    apply %get(%stack) : $@convention(thin) () -> @out S
    cond_br undef, left, right
left:
    apply %other() : $@convention(thin) () -> ()
    %new = apply %get_value() : $@convention(thin) () -> @owned S
    store %new to [assign] %stack : $*S
    apply %see_addr(%stack) : $@convention(thin) (@in_guaranteed S) -> ()
    apply %other() : $@convention(thin) () -> ()
    br bottom
right:
    %copy = load [copy] %stack : $*S
    apply %end(%copy) : $@convention(thin) (@owned S) -> ()
    br bottom
bottom:
    destroy_addr %stack : $*S
    dealloc_stack %stack_addr : $*S
    %retval = tuple ()
    return %retval : $()
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// }} Multiple blocks
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// =============================================================================
// =============================================================================
// }} Multiple defs
// =============================================================================
// =============================================================================

// #############################################################################
// #############################################################################
// }} SCALAR STORAGE
// #############################################################################
// #############################################################################

// #############################################################################
// #############################################################################
// AGGREGATE STORAGE                                                          {{
// #############################################################################
// #############################################################################

@_moveOnly struct S2 {
    var s1: S
    var s2: S
}

sil [ossa] @get_value_S2 : $@convention(thin) () -> @owned S2
sil [ossa] @end_S2 : $@convention(thin) (@owned S2) -> ()

@_moveOnly struct S3 {
    var s1: S
    var s2: S
    var s3: S
}

sil [ossa] @get_value_S3 : $@convention(thin) () -> @owned S3
sil [ossa] @end_S3 : $@convention(thin) (@owned S3) -> ()

// =============================================================================
// =============================================================================
// Single def                                                                 {{
// =============================================================================
// =============================================================================

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Single block                                                               {{
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// The apply of other remains before the destroy_addr.
// CHECK-LABEL: sil [ossa] @aggregate_1 : {{.*}} {
// CHECK:         [[OTHER:%[^,]+]] = function_ref @other
// CHECK:         [[STACK:%[^,]+]] = alloc_stack
// CHECK:         apply [[OTHER]]()
// CHECK:         destroy_addr [[STACK]]
// CHECK-LABEL: } // end sil function 'aggregate_1'
sil [ossa] @aggregate_1 : $@convention(thin) () -> () {
bb0:
  %get_value_S2 = function_ref @get_value_S2 : $@convention(thin) () -> @owned S2
  %end = function_ref @end : $@convention(thin) (@owned S) -> ()
  %other = function_ref @other : $@convention(thin) () -> ()

  %stack_addr = alloc_stack $S2
  %stack = mark_unresolved_non_copyable_value [consumable_and_assignable] %stack_addr : $*S2
  %instance_1 = apply %get_value_S2() : $@convention(thin) () -> @owned S2
  store %instance_1 to [init] %stack : $*S2
  apply %other() : $@convention(thin) () -> ()
  destroy_addr %stack : $*S2
  dealloc_stack %stack_addr : $*S2
  %retval = tuple ()
  return %retval : $()
}


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// }} Single block
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// =============================================================================
// =============================================================================
// }} Single def
// =============================================================================
// =============================================================================

// =============================================================================
// =============================================================================
// Multiple defs                                                              {{
// =============================================================================
// =============================================================================

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Single block                                                               {{
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// Calls to other before each destroy remain before.
// CHECK-LABEL: sil [ossa] @aggregate_2 : {{.*}} {
// CHECK:         [[OTHER:%[^,]+]] = function_ref @other
// CHECK:         [[STACK:%[^,]+]] = alloc_stack
// CHECK:         apply [[OTHER]]()
// CHECK:         destroy_addr [[STACK]] : $*S2
// CHECK:         apply [[OTHER]]()
// CHECK:         destroy_addr [[STACK]] : $*S2
// CHECK-LABEL: } // end sil function 'aggregate_2'
sil [ossa] @aggregate_2 : $@convention(thin) () -> () {
bb0:
  %get_value_S2 = function_ref @get_value_S2 : $@convention(thin) () -> @owned S2
  %end = function_ref @end : $@convention(thin) (@owned S) -> ()
  %other = function_ref @other : $@convention(thin) () -> ()

  %stack_addr = alloc_stack $S2
  %stack = mark_unresolved_non_copyable_value [consumable_and_assignable] %stack_addr : $*S2
  %instance_1 = apply %get_value_S2() : $@convention(thin) () -> @owned S2
  store %instance_1 to [init] %stack : $*S2
  %instance_2 = apply %get_value_S2() : $@convention(thin) () -> @owned S2
  apply %other() : $@convention(thin) () -> ()
  store %instance_2 to [assign] %stack : $*S2
  apply %other() : $@convention(thin) () -> ()
  destroy_addr %stack : $*S2
  dealloc_stack %stack_addr : $*S2
  %retval = tuple ()
  return %retval : $()
}

// s1 is consumed but s2 is not and so is not destroyed until function end, after
// other.

// CHECK-LABEL: sil [ossa] @simpleTestVar2 : {{.*}} {
// CHECK:         [[OTHER:%[^,]+]] = function_ref @other
// CHECK:         [[STACK:%[^,]+]] = alloc_stack
// CHECK:         apply [[OTHER]]()
// CHECK:         [[S2_ADDR:%[^,]+]] = struct_element_addr [[STACK]] : $*S2, #S2.s2
// CHECK:         destroy_addr [[S2_ADDR]]
// CHECK-LABEL: } // end sil function 'simpleTestVar2'
sil [ossa] @simpleTestVar2 : $@convention(thin) () -> () {
bb0:
  %get_value_S2 = function_ref @get_value_S2 : $@convention(thin) () -> @owned S2
  %end = function_ref @end : $@convention(thin) (@owned S) -> ()
  %other = function_ref @other : $@convention(thin) () -> ()

  %stack_addr = alloc_stack $S2
  %stack = mark_unresolved_non_copyable_value [consumable_and_assignable] %stack_addr : $*S2
  %instance_1 = apply %get_value_S2() : $@convention(thin) () -> @owned S2
  store %instance_1 to [init] %stack : $*S2
  %instance_2 = apply %get_value_S2() : $@convention(thin) () -> @owned S2
  %access = begin_access [modify] [static] %stack : $*S2
  store %instance_2 to [assign] %access : $*S2
  end_access %access : $*S2
  %access_2 = begin_access [deinit] [static] %stack : $*S2
  %s1_addr = struct_element_addr %access_2 : $*S2, #S2.s1
  %s1 = load [copy] %s1_addr : $*S
  apply %end(%s1) : $@convention(thin) (@owned S) -> ()
  end_access %access_2 : $*S2
  apply %other() : $@convention(thin) () -> ()
  destroy_addr %stack : $*S2
  dealloc_stack %stack_addr : $*S2
  %retval = tuple ()
  return %retval : $()
}

// Both fields (#S2.s1, #S2.s2) are consumed before other.
// CHECK-LABEL: sil [ossa] @simpleTestVar3 : {{.*}} {
// CHECK:         [[END:%[^,]+]] = function_ref @end
// CHECK:         [[OTHER:%[^,]+]] = function_ref @other
// CHECK:         [[STACK:%[^,]+]] = alloc_stack
// CHECK:         begin_access
// CHECK:         [[ACCESS_1:%[^,]+]] = begin_access [modify] [static] [[STACK]]
// CHECK:         [[S1_ADDR:%[^,]+]] = struct_element_addr [[ACCESS_1]] : $*S2, #S2.s1
// CHECK:         [[S1:%[^,]+]] = load [take] [[S1_ADDR]]
// CHECK:         apply [[END]]([[S1]])
// CHECK:         [[ACCESS_2:%[^,]+]] = begin_access [modify] [static] [[STACK]]
// CHECK:         [[S2_ADDR:%[^,]+]] = struct_element_addr [[ACCESS_2]] : $*S2, #S2.s2
// CHECK:         [[S2:%[^,]+]] = load [take] [[S2_ADDR]]
// CHECK:         apply [[END]]([[S2]])
// CHECK:         apply [[OTHER]]()
// CHECK-LABEL: } // end sil function 'simpleTestVar3'
sil [ossa] @simpleTestVar3 : $@convention(thin) () -> () {
bb0:
  %get_value_S2 = function_ref @get_value_S2 : $@convention(thin) () -> @owned S2
  %end = function_ref @end : $@convention(thin) (@owned S) -> ()
  %other = function_ref @other : $@convention(thin) () -> ()

  %stack_addr = alloc_stack $S2
  %stack = mark_unresolved_non_copyable_value [consumable_and_assignable] %stack_addr : $*S2
  %instance_1 = apply %get_value_S2() : $@convention(thin) () -> @owned S2
  store %instance_1 to [init] %stack : $*S2
  %instance_2 = apply %get_value_S2() : $@convention(thin) () -> @owned S2
  %access = begin_access [modify] [static] %stack : $*S2
  store %instance_2 to [assign] %access : $*S2
  end_access %access : $*S2
  %access_2 = begin_access [deinit] [static] %stack : $*S2
  %s1_addr = struct_element_addr %access_2 : $*S2, #S2.s1
  %s1 = load [copy] %s1_addr : $*S
  apply %end(%s1) : $@convention(thin) (@owned S) -> ()
  end_access %access_2 : $*S2
  %access_3 = begin_access [deinit] [static] %stack : $*S2
  %s2_addr = struct_element_addr %access_3 : $*S2, #S2.s2
  %s2 = load [copy] %s2_addr : $*S
  apply %end(%s2) : $@convention(thin) (@owned S) -> ()
  end_access %access_3 : $*S2
  apply %other() : $@convention(thin) () -> ()
  destroy_addr %stack : $*S2
  dealloc_stack %stack_addr : $*S2
  %retval = tuple ()
  return %retval : $()
}

// Addr is initialized, then both fields are individually consumed before other.
// Then addr is initialized again and neither field is consumed; then other is
// applied again.
//
// Ensure that the reinitialized fields survive to function end.
//
// CHECK-LABEL: sil [ossa] @simpleTestVar3a : {{.*}} {
// CHECK:         [[GET_VALUE_S2:%[^,]+]] = function_ref @get_value_S2
// CHECK:         [[OTHER:%[^,]+]] = function_ref @other
// CHECK:         [[STACK:%[^,]+]] = alloc_stack
// CHECK:         apply [[OTHER]]()
// CHECK:         [[INSTANCE_3:%[^,]+]] = apply [[GET_VALUE_S2]]()
// CHECK:         [[ACCESS:%[^,]+]] = begin_access [modify] [static] [[STACK]]
// CHECK:         store [[INSTANCE_3]] to [init] [[ACCESS]]
// CHECK:         end_access [[ACCESS]]
// CHECK:         apply [[OTHER]]() : $@convention(thin) () -> ()
// CHECK:         destroy_addr [[STACK]]
// CHECK-LABEL: } // end sil function 'simpleTestVar3a'
sil [ossa] @simpleTestVar3a : $@convention(thin) () -> () {
bb0:
  %get_value_S2 = function_ref @get_value_S2 : $@convention(thin) () -> @owned S2
  %end = function_ref @end : $@convention(thin) (@owned S) -> ()
  %other = function_ref @other : $@convention(thin) () -> ()

  %stack_addr = alloc_stack $S2
  %stack = mark_unresolved_non_copyable_value [consumable_and_assignable] %stack_addr : $*S2
  %instance_1 = apply %get_value_S2() : $@convention(thin) () -> @owned S2
  store %instance_1 to [init] %stack : $*S2
  %instance_2 = apply %get_value_S2() : $@convention(thin) () -> @owned S2
  %access_1 = begin_access [modify] [static] %stack : $*S2
  store %instance_2 to [assign] %access_1 : $*S2
  end_access %access_1 : $*S2
  %access_2 = begin_access [deinit] [static] %stack : $*S2
  %s1_addr = struct_element_addr %access_2 : $*S2, #S2.s1
  %s1 = load [copy] %s1_addr : $*S
  apply %end(%s1) : $@convention(thin) (@owned S) -> ()
  end_access %access_2 : $*S2
  %access_3 = begin_access [deinit] [static] %stack : $*S2
  %s2_addr = struct_element_addr %access_3 : $*S2, #S2.s2
  %s2 = load [copy] %s2_addr : $*S
  apply %end(%s2) : $@convention(thin) (@owned S) -> ()
  end_access %access_3 : $*S2
  apply %other() : $@convention(thin) () -> ()
  %instance_3 = apply %get_value_S2() : $@convention(thin) () -> @owned S2
  %access_4 = begin_access [modify] [static] %stack : $*S2
  store %instance_3 to [assign] %access_4 : $*S2
  end_access %access_4 : $*S2
  apply %other() : $@convention(thin) () -> ()
  destroy_addr %stack : $*S2
  dealloc_stack %stack_addr : $*S2
  %retval = tuple ()
  return %retval : $()
}

// Like simpleTestVar3a but without access scopes and the original init.
// CHECK-LABEL: sil [ossa] @simpleTestVar3a_simplified : {{.*}} {
// CHECK:         [[GET_VALUE_S2:%[^,]+]] = function_ref @get_value_S2
// CHECK:         [[OTHER:%[^,]+]] = function_ref @other
// CHECK:         [[STACK:%[^,]+]] = alloc_stack
// CHECK:         apply [[OTHER]]()
// CHECK:         [[INSTANCE_2:%[^,]+]] = apply [[GET_VALUE_S2]]()
// CHECK:         store [[INSTANCE_2]] to [init] [[STACK]]
// CHECK:         apply [[OTHER]]() : $@convention(thin) () -> ()
// CHECK:         destroy_addr [[STACK]]
// CHECK-LABEL: } // end sil function 'simpleTestVar3a_simplified'
sil [ossa] @simpleTestVar3a_simplified : $@convention(thin) () -> () {
bb0:
  %get_value_S2 = function_ref @get_value_S2 : $@convention(thin) () -> @owned S2
  %end = function_ref @end : $@convention(thin) (@owned S) -> ()
  %other = function_ref @other : $@convention(thin) () -> ()

  %stack_addr = alloc_stack $S2
  %stack = mark_unresolved_non_copyable_value [consumable_and_assignable] %stack_addr : $*S2
  %instance_1 = apply %get_value_S2() : $@convention(thin) () -> @owned S2
  store %instance_1 to [init] %stack : $*S2
  %s1_addr = struct_element_addr %stack : $*S2, #S2.s1
  %s1 = load [copy] %s1_addr : $*S
  apply %end(%s1) : $@convention(thin) (@owned S) -> ()
  %s2_addr = struct_element_addr %stack : $*S2, #S2.s2
  %s2 = load [copy] %s2_addr : $*S
  apply %end(%s2) : $@convention(thin) (@owned S) -> ()
  apply %other() : $@convention(thin) () -> ()
  %instance_2 = apply %get_value_S2() : $@convention(thin) () -> @owned S2
  store %instance_2 to [assign] %stack : $*S2
  apply %other() : $@convention(thin) () -> ()
  destroy_addr %stack : $*S2
  dealloc_stack %stack_addr : $*S2
  %retval = tuple ()
  return %retval : $()
}

// Ensure that first initialized liveness remains until original destroy.
// And ensure that reinitialized fields live until function exit.
// CHECK-LABEL: sil [ossa] @simpleTestVar3a_simplified_vary2 : {{.*}} {
// CHECK:         [[GET_VALUE:%[^,]+]] = function_ref @get_value
// CHECK:         [[SEE:%[^,]+]] = function_ref @see
// CHECK:         [[OTHER:%[^,]+]] = function_ref @other
// CHECK:         [[STACK:%[^,]+]] = alloc_stack $S
// CHECK:         [[INSTANCE_1:%[^,]+]] = apply [[GET_VALUE]]()
// CHECK:         store [[INSTANCE_1]] to [init] [[STACK]]
// CHECK:         [[BORROW:%[^,]+]] = load_borrow [[STACK]]
// CHECK:         apply [[SEE]]([[BORROW]])
// CHECK:         end_borrow [[BORROW]]
// CHECK:         apply [[OTHER]]()
// CHECK:         [[INSTANCE_2:%[^,]+]] = apply [[GET_VALUE]]()
// CHECK:         destroy_addr [[STACK]]
// CHECK:         store [[INSTANCE_2]] to [init] [[STACK]]
// CHECK:         apply [[OTHER]]()
// CHECK:         destroy_addr [[STACK]]
// CHECK-LABEL: } // end sil function 'simpleTestVar3a_simplified_vary2'
sil [ossa] @simpleTestVar3a_simplified_vary2 : $@convention(thin) () -> () {
bb0:
  %get_value = function_ref @get_value : $@convention(thin) () -> @owned S
  %see = function_ref @see : $@convention(thin) (@guaranteed S) -> ()
  %other = function_ref @other : $@convention(thin) () -> ()

  %stack_addr = alloc_stack $S
  %stack = mark_unresolved_non_copyable_value [consumable_and_assignable] %stack_addr : $*S
  %instance_1 = apply %get_value() : $@convention(thin) () -> @owned S
  store %instance_1 to [init] %stack : $*S
  %s = load_borrow %stack : $*S
  apply %see(%s) : $@convention(thin) (@guaranteed S) -> ()
  end_borrow %s : $S
  apply %other() : $@convention(thin) () -> ()
  %instance_2 = apply %get_value() : $@convention(thin) () -> @owned S
  store %instance_2 to [assign] %stack : $*S
  apply %other() : $@convention(thin) () -> ()
  destroy_addr %stack : $*S
  dealloc_stack %stack_addr : $*S
  %retval = tuple ()
  return %retval : $()
}

// s1 is consumed at @end.  s2 is never consumed so it's destroyed at function
// end.
// CHECK-LABEL: sil [ossa] @simpleTestVar3b : {{.*}} {
// CHECK:         [[END:%[^,]+]] = function_ref @end
// CHECK:         [[OTHER:%[^,]+]] = function_ref @other
// CHECK:         [[STACK:%[^,]+]] = alloc_stack
// CHECK:         begin_access
// CHECK:         [[ACCESS:%[^,]+]] = begin_access [modify] [static] [[STACK]]
// CHECK:         [[S1_ADDR:%[^,]+]] = struct_element_addr [[ACCESS]] : $*S2, #S2.s1
// CHECK:         [[S1:%[^,]+]] = load [take] [[S1_ADDR]]
// CHECK:         apply [[END]]([[S1]])
// CHECK:         apply [[OTHER]]()
// CHECK:         [[S2_ADDR:%[^,]+]] = struct_element_addr [[STACK]] : $*S2, #S2.s2
// CHECK:         destroy_addr [[S2_ADDR]]
// CHECK-LABEL: } // end sil function 'simpleTestVar3b'
sil [ossa] @simpleTestVar3b : $@convention(thin) () -> () {
bb0:
  %get_value_S2 = function_ref @get_value_S2 : $@convention(thin) () -> @owned S2
  %end = function_ref @end : $@convention(thin) (@owned S) -> ()
  %see = function_ref @see : $@convention(thin) (@guaranteed S) -> ()
  %other = function_ref @other : $@convention(thin) () -> ()

  %stack_addr = alloc_stack $S2
  %stack = mark_unresolved_non_copyable_value [consumable_and_assignable] %stack_addr : $*S2
  %instance_1 = apply %get_value_S2() : $@convention(thin) () -> @owned S2
  store %instance_1 to [init] %stack : $*S2
  %instance_2 = apply %get_value_S2() : $@convention(thin) () -> @owned S2
  %access_1 = begin_access [modify] [static] %stack : $*S2
  store %instance_2 to [assign] %access_1 : $*S2
  end_access %access_1 : $*S2
  %access_2 = begin_access [deinit] [static] %stack : $*S2
  %s1_addr = struct_element_addr %access_2 : $*S2, #S2.s1
  %s1 = load [copy] %s1_addr : $*S
  apply %end(%s1) : $@convention(thin) (@owned S) -> ()
  end_access %access_2 : $*S2
  %access_3 = begin_access [read] [static] %stack : $*S2
  %s2_addr = struct_element_addr %access_3 : $*S2, #S2.s2
  %s2 = load [copy] %s2_addr : $*S
  apply %see(%s2) : $@convention(thin) (@guaranteed S) -> ()
  destroy_value %s2 : $S
  end_access %access_3 : $*S2
  apply %other() : $@convention(thin) () -> ()
  destroy_addr %stack : $*S2
  dealloc_stack %stack_addr : $*S2
  %retval = tuple ()
  return %retval : $()
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// }} Single block
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// {{ Multiple blocks
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// Ensure that liveness extends to destroy in live-at-entry block where no def
// precedes destroy.  And ensure that the reinit stack stays live until
// function exit.
// CHECK-LABEL: sil [ossa] @simpleTestVar3a_simplified_vary : {{.*}} {
// CHECK:         [[GET_VALUE_S2:%[^,]+]] = function_ref @get_value_S2
// CHECK:         [[SEE:%[^,]+]] = function_ref @see
// CHECK:         [[OTHER:%[^,]+]] = function_ref @other
// CHECK:         [[STACK:%[^,]+]] = alloc_stack $S2
// CHECK:         [[INSTANCE_1:%[^,]+]] = apply [[GET_VALUE_S2]]()
// CHECK:         store [[INSTANCE_1]] to [init] [[STACK]]
// CHECK:         [[S1_ADDR:%[^,]+]] = struct_element_addr [[STACK]]
// CHECK:         [[S1:%[^,]+]] = load_borrow [[S1_ADDR]]
// CHECK:         apply [[SEE]]([[S1]])
// CHECK:         end_borrow [[S1]]
// CHECK:         [[S2_ADDR:%[^,]+]] = struct_element_addr [[STACK]]
// CHECK:         [[S2:%[^,]+]] = load_borrow [[S2_ADDR]]
// CHECK:         apply [[SEE]]([[S2]])
// CHECK:         end_borrow [[S2]]
// CHECK:         apply [[OTHER]]()
// CHECK:         [[INSTANCE_2:%[^,]+]] = apply [[GET_VALUE_S2]]()
// CHECK:         br bb1
// CHECK:       bb1:
// CHECK:         destroy_addr [[STACK]]
// CHECK:         store [[INSTANCE_2]] to [init] [[STACK]]
// CHECK:         apply [[OTHER]]()
// CHECK:         destroy_addr [[STACK]]
// CHECK-LABEL: } // end sil function 'simpleTestVar3a_simplified_vary'
sil [ossa] @simpleTestVar3a_simplified_vary : $@convention(thin) () -> () {
bb0:
  %get_value_S2 = function_ref @get_value_S2 : $@convention(thin) () -> @owned S2
  %see = function_ref @see : $@convention(thin) (@guaranteed S) -> ()
  %other = function_ref @other : $@convention(thin) () -> ()

  %stack_addr = alloc_stack $S2
  %stack = mark_unresolved_non_copyable_value [consumable_and_assignable] %stack_addr : $*S2
  %instance_1 = apply %get_value_S2() : $@convention(thin) () -> @owned S2
  store %instance_1 to [init] %stack : $*S2
  %s1_addr = struct_element_addr %stack : $*S2, #S2.s1
  %s1 = load_borrow %s1_addr : $*S
  apply %see(%s1) : $@convention(thin) (@guaranteed S) -> ()
  end_borrow %s1 : $S
  %s2_addr = struct_element_addr %stack : $*S2, #S2.s2
  %s2 = load_borrow %s2_addr : $*S
  apply %see(%s2) : $@convention(thin) (@guaranteed S) -> ()
  end_borrow %s2 : $S
  apply %other() : $@convention(thin) () -> ()
  %instance_3 = apply %get_value_S2() : $@convention(thin) () -> @owned S2
  br bb1
bb1:
  store %instance_3 to [assign] %stack : $*S2
  apply %other() : $@convention(thin) () -> ()
  destroy_addr %stack : $*S2
  dealloc_stack %stack_addr : $*S2
  %retval = tuple ()
  return %retval : $()
}

// Stack is initialized twice, in entry and middle.  In each case, it is passed
// to a consuming function on the left block and unused on the right block; and
// each right block contains an apply of other.
//
// Verify that the destroy in each right block is after the apply of other.
// CHECK-LABEL: sil [ossa] @simpleTestVar4 : {{.*}} {
// CHECK:         [[OTHER:%[^,]+]] = function_ref @other
// CHECK:         [[STACK:%[^,]+]] = alloc_stack
// CHECK:         cond_br {{%[^,]+}}, [[LEFT_1:bb[0-9]+]], [[RIGHT_1:bb[0-9]+]]
// CHECK:       [[LEFT_1]]:
// CHECK:         br [[MIDDLE:bb[0-9]+]]
// CHECK:       [[RIGHT_1]]:
// CHECK:         apply [[OTHER]]()
// CHECK:         destroy_addr [[STACK]]
// CHECK:         br [[MIDDLE]]
// CHECK:       [[MIDDLE]]:
// CHECK:         cond_br {{%[^,]+}}, [[LEFT_2:bb[0-9]+]], [[RIGHT_2:bb[0-9]+]]
// CHECK:       [[LEFT_2]]:
// CHECK:         br [[EXIT:bb[0-9]+]]
// CHECK:       [[RIGHT_2]]:
// CHECK:         destroy_addr [[STACK]]
// CHECK:         apply [[OTHER]]() : $@convention(thin) () -> ()
// CHECK:         br [[EXIT]]
// CHECK-LABEL: } // end sil function 'simpleTestVar4'
sil [ossa] @simpleTestVar4 : $@convention(thin) () -> () {
entry:
  %get_value_S2 = function_ref @get_value_S2 : $@convention(thin) () -> @owned S2
  %condition = function_ref @condition : $@convention(thin) () -> Builtin.Int1
  %end_S2 = function_ref @end_S2 : $@convention(thin) (@owned S2) -> ()
  %other = function_ref @other : $@convention(thin) () -> ()

  %stack_addr = alloc_stack $S2
  %stack = mark_unresolved_non_copyable_value [consumable_and_assignable] %stack_addr : $*S2
  %instance_1 = apply %get_value_S2() : $@convention(thin) () -> @owned S2
  store %instance_1 to [init] %stack : $*S2
  %instance_2 = apply %get_value_S2() : $@convention(thin) () -> @owned S2
  %access_1 = begin_access [modify] [static] %stack : $*S2
  store %instance_2 to [assign] %access_1 : $*S2
  end_access %access_1 : $*S2
  %which_1 = apply %condition() : $@convention(thin) () -> Builtin.Int1
  cond_br %which_1, left_1, right_1

left_1:
  %access_2 = begin_access [deinit] [static] %stack : $*S2
  %reload_1 = load [copy] %access_2 : $*S2
  apply %end_S2(%reload_1) : $@convention(thin) (@owned S2) -> ()
  end_access %access_2 : $*S2
  br middle

right_1:
  apply %other() : $@convention(thin) () -> ()
  br middle

middle:
  %instance_3 = apply %get_value_S2() : $@convention(thin) () -> @owned S2
  %access_3 = begin_access [modify] [static] %stack : $*S2
  store %instance_3 to [assign] %access_3 : $*S2
  end_access %access_3 : $*S2
  %which_2 = apply %condition() : $@convention(thin) () -> Builtin.Int1
  cond_br %which_2, left_2, right_2

left_2:
  %access_4 = begin_access [deinit] [static] %stack : $*S2
  %reload_2 = load [copy] %access_4 : $*S2
  apply %end_S2(%reload_2) : $@convention(thin) (@owned S2) -> ()
  end_access %access_4 : $*S2
  br end

right_2:
  apply %other() : $@convention(thin) () -> ()
  br end

end:
  %retval = tuple ()
  destroy_addr %stack : $*S2
  dealloc_stack %stack_addr : $*S2
  return %retval : $() 
}

// One field is consumed in either branch: s1 in left, s2 in right.  The other
// field should live until the end of the block.
// CHECK-LABEL: sil [ossa] @simpleTestVar6 : $@convention(thin) () -> () {
// CHECK:         [[OTHER:%[^,]+]] = function_ref @other
// CHECK:         [[STACK:%[^,]+]] = alloc_stack
// CHECK:         cond_br {{%[^,]+}}, [[LEFT:bb[0-9]+]], [[RIGHT:bb[0-9]+]]
// CHECK:       [[LEFT]]:
// CHECK:         apply [[OTHER]]()
// CHECK:         [[S2_ADDR:%[^,]+]] = struct_element_addr [[STACK]] : $*S2, #S2.s2
// CHECK:         destroy_addr [[S2_ADDR]] : $*S
// CHECK:         br [[EXIT:bb[0-9]+]]
// CHECK:       [[RIGHT]]:
// CHECK:         apply [[OTHER]]()
// CHECK:         [[S1_ADDR:%[^,]+]] = struct_element_addr [[STACK]] : $*S2, #S2.s1
// CHECK:         destroy_addr [[S1_ADDR]] : $*S
// CHECK:         br [[EXIT]]
// CHECK:       [[EXIT]]:
// CHECK-LABEL: } // end sil function 'simpleTestVar6'
sil [ossa] @simpleTestVar6 : $@convention(thin) () -> () {
entry:
  %get_value_S2 = function_ref @get_value_S2 : $@convention(thin) () -> @owned S2
  %condition = function_ref @condition : $@convention(thin) () -> Builtin.Int1
  %other = function_ref @other : $@convention(thin) () -> ()
  %end = function_ref @end : $@convention(thin) (@owned S) -> ()

  %stack_addr = alloc_stack $S2
  %stack = mark_unresolved_non_copyable_value [consumable_and_assignable] %stack_addr : $*S2
  %instance_1 = apply %get_value_S2() : $@convention(thin) () -> @owned S2
  store %instance_1 to [init] %stack : $*S2
  %instance_2 = apply %get_value_S2() : $@convention(thin) () -> @owned S2
  %access_1 = begin_access [modify] [static] %stack : $*S2
  store %instance_2 to [assign] %access_1 : $*S2
  end_access %access_1 : $*S2
  %which = apply %condition() : $@convention(thin) () -> Builtin.Int1
  cond_br %which, left, right

left:
  %access_2 = begin_access [deinit] [static] %stack : $*S2
  %s1_addr = struct_element_addr %access_2 : $*S2, #S2.s1
  %s1 = load [copy] %s1_addr : $*S
  apply %end(%s1) : $@convention(thin) (@owned S) -> ()
  end_access %access_2 : $*S2
  apply %other() : $@convention(thin) () -> ()
  br exit

right:
  %access_3 = begin_access [deinit] [static] %stack : $*S2
  %s2_addr = struct_element_addr %access_3 : $*S2, #S2.s2
  %s2 = load [copy] %s2_addr : $*S
  apply %end(%s2) : $@convention(thin) (@owned S) -> ()
  end_access %access_3 : $*S2
  apply %other() : $@convention(thin) () -> ()
  br exit

exit:
  %instance_3 = apply %get_value_S2() : $@convention(thin) () -> @owned S2
  %access_4 = begin_access [modify] [static] %stack : $*S2
  store %instance_3 to [assign] %access_4 : $*S2
  end_access %access_4 : $*S2
  destroy_addr %stack : $*S2
  dealloc_stack %stack_addr : $*S2
  %retval = tuple ()
  return %retval : $()
}

// The struct has three fields: 
//   s1 is consumed in left but not right
//   s2 is consumed in right but not left
//   s3 is not consumed
// There is an apply of other after the consumes and at the beginning of exit.
//
// Ensure that the not-consumed-on-this-branch field (s2 in left, s1 in right)
// is destroyed after the apply of other in each branch block.  Ensure that the
// unconsumed field is destroyed at function exit--after the apply of other in
// exit.
// CHECK-LABEL: sil [ossa] @simpleTestVar6a : $@convention(thin) () -> () {
// CHECK:         [[OTHER:%[^,]+]] = function_ref @other : $@convention(thin) () -> () 
// CHECK:         [[STACK:%[^,]+]] = alloc_stack $S3                            
// CHECK:         cond_br {{%[^,]+}}, [[LEFT:bb[0-9]+]], [[RIGHT:bb[0-9]+]]                           
// CHECK:       [[LEFT]]:                                              
// CHECK:         apply [[OTHER]]() : $@convention(thin) () -> ()
// CHECK:         [[S2_ADDR:%[^,]+]] = struct_element_addr [[STACK]] : $*S3, #S3.s2     
// CHECK:         destroy_addr [[S2_ADDR]] : $*S                          
// CHECK:         br [[EXIT:bb[0-9]+]]                                          
// CHECK:       [[RIGHT]]:                                              
// CHECK:         apply [[OTHER]]() : $@convention(thin) () -> ()
// CHECK:         [[S1_ADDR:%[^,]+]] = struct_element_addr [[STACK]] : $*S3, #S3.s1     
// CHECK:         destroy_addr [[S1_ADDR]] : $*S                          
// CHECK:         br [[EXIT]]                                          
// CHECK:       [[EXIT]]:                                              
// CHECK:         apply [[OTHER]]() : $@convention(thin) () -> ()
// CHECK:         [[S3_ADDR:%[^,]+]] = struct_element_addr [[STACK]] : $*S3, #S3.s3     
// CHECK:         destroy_addr [[S3_ADDR]] : $*S                          
// CHECK-LABEL: } // end sil function 'simpleTestVar6a'
sil [ossa] @simpleTestVar6a : $@convention(thin) () -> () {
bb0:
  %condition = function_ref @condition : $@convention(thin) () -> Builtin.Int1
  %end = function_ref @end : $@convention(thin) (@owned S) -> ()
  %get_value_S3 = function_ref @get_value_S3 : $@convention(thin) () -> @owned S3
  %other = function_ref @other : $@convention(thin) () -> ()

  %stack_addr = alloc_stack $S3
  %stack = mark_unresolved_non_copyable_value [consumable_and_assignable] %stack_addr : $*S3
  %instance_1 = apply %get_value_S3() : $@convention(thin) () -> @owned S3
  store %instance_1 to [init] %stack : $*S3
  %instance_2 = apply %get_value_S3() : $@convention(thin) () -> @owned S3
  %access_1 = begin_access [modify] [static] %stack : $*S3
  store %instance_2 to [assign] %access_1 : $*S3
  end_access %access_1 : $*S3
  %which = apply %condition() : $@convention(thin) () -> Builtin.Int1  
  cond_br %which, left, right

left:
  %access_2 = begin_access [deinit] [static] %stack : $*S3
  %s1_addr = struct_element_addr %access_2 : $*S3, #S3.s1
  %s1 = load [copy] %s1_addr : $*S
  apply %end(%s1) : $@convention(thin) (@owned S) -> ()
  end_access %access_2 : $*S3
  apply %other() : $@convention(thin) () -> ()
  br exit

right:
  %access_3 = begin_access [deinit] [static] %stack : $*S3
  %s2_addr = struct_element_addr %access_3 : $*S3, #S3.s2
  %s2 = load [copy] %s2_addr : $*S
  apply %end(%s2) : $@convention(thin) (@owned S) -> ()
  end_access %access_3 : $*S3
  apply %other() : $@convention(thin) () -> ()
  br exit

exit:
  apply %other() : $@convention(thin) () -> ()
  destroy_addr %stack : $*S3
  dealloc_stack %stack_addr : $*S3
  %retval = tuple ()
  return %retval : $()
}

/// The fields #S3.s1 and #S3.s3 are consumed in left but not right.
/// So they should be live until the end of right.
/// The field #S3.s2 is consumed in right but not left.
/// So it should be live until the end of left.
///
// CHECK-LABEL: sil [ossa] @simpleTestVar6b : {{.*}} {
// CHECK:       {{bb[0-9]+}}:
// CHECK:         [[OTHER:%[^,]+]] = function_ref @other
// CHECK:         [[STACK:%[^,]+]] = alloc_stack
// CHECK:         cond_br {{%[^,]+}}, [[LEFT:bb[0-9]+]], [[RIGHT:bb[0-9]+]]
// CHECK:       [[LEFT]]:
// CHECK:         apply [[OTHER]]()
// CHECK:         [[S2_ADDR:%[^,]+]] = struct_element_addr [[STACK]] : $*S3, #S3.s2
// CHECK:         destroy_addr [[S2_ADDR]]
// CHECK:         br [[EXIT:bb[0-9]+]]
// CHECK:       [[RIGHT]]:
// CHECK:         apply [[OTHER]]()
// CHECK:         [[S3_ADDR:%[^,]+]] = struct_element_addr [[STACK]] : $*S3, #S3.s3
// CHECK:         destroy_addr [[S3_ADDR]]
// CHECK:         [[S1_ADDR:%[^,]+]] = struct_element_addr [[STACK]] : $*S3, #S3.s1
// CHECK:         destroy_addr [[S1_ADDR]]
// CHECK:         br [[EXIT]]
// CHECK:       [[EXIT]]:
// CHECK-LABEL: } // end sil function 'simpleTestVar6b'
sil [ossa] @simpleTestVar6b : $@convention(thin) () -> () {
entry:
  %condition = function_ref @condition : $@convention(thin) () -> Builtin.Int1
  %end = function_ref @end : $@convention(thin) (@owned S) -> ()
  %get_value_S3 = function_ref @get_value_S3 : $@convention(thin) () -> @owned S3
  %other = function_ref @other : $@convention(thin) () -> ()

  %stack_addr = alloc_stack $S3
  %stack = mark_unresolved_non_copyable_value [consumable_and_assignable] %stack_addr : $*S3
  %instance_1 = apply %get_value_S3() : $@convention(thin) () -> @owned S3
  store %instance_1 to [init] %stack : $*S3
  %instance_2 = apply %get_value_S3() : $@convention(thin) () -> @owned S3
  %access_1 = begin_access [modify] [static] %stack : $*S3
  store %instance_2 to [assign] %access_1 : $*S3
  end_access %access_1 : $*S3
  %which = apply %condition() : $@convention(thin) () -> Builtin.Int1
  cond_br %which, left, right

left:
  %access_2 = begin_access [deinit] [static] %stack : $*S3
  %s1_addr = struct_element_addr %access_2 : $*S3, #S3.s1
  %s1 = load [copy] %s1_addr : $*S
  apply %end(%s1) : $@convention(thin) (@owned S) -> ()
  end_access %access_2 : $*S3
  %access_3 = begin_access [deinit] [static] %stack : $*S3
  %s3_addr = struct_element_addr %access_3 : $*S3, #S3.s3
  %s3 = load [copy] %s3_addr : $*S
  apply %end(%s3) : $@convention(thin) (@owned S) -> ()
  end_access %access_3 : $*S3
  apply %other() : $@convention(thin) () -> ()
  br exit

right:
  %access_4 = begin_access [deinit] [static] %stack : $*S3
  %s2_addr = struct_element_addr %access_4 : $*S3, #S3.s2
  %s2 = load [copy] %s2_addr : $*S
  apply %end(%s2) : $@convention(thin) (@owned S) -> ()
  end_access %access_4 : $*S3
  apply %other() : $@convention(thin) () -> ()
  br exit

exit:
  apply %other() : $@convention(thin) () -> ()
  destroy_addr %stack : $*S3
  dealloc_stack %stack_addr : $*S3
  %retval = tuple ()
  return %retval : $()
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// }} Multiple blocks
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// =============================================================================
// =============================================================================
// }} Multiple defs
// =============================================================================
// =============================================================================

// #############################################################################
// #############################################################################
// }} AGGREGATE STORAGE
// #############################################################################
// #############################################################################