File tree Expand file tree Collapse file tree 3 files changed +65
-10
lines changed
lib/SILOptimizer/Mandatory Expand file tree Collapse file tree 3 files changed +65
-10
lines changed Original file line number Diff line number Diff line change @@ -497,6 +497,9 @@ static bool isInOutDefThatNeedsEndOfFunctionLiveness(MarkMustCheckInst *markedAd
497
497
498
498
if (isa<RefElementAddrInst>(stripAccessMarkers (operand)))
499
499
return true ;
500
+
501
+ if (isa<GlobalAddrInst>(stripAccessMarkers (operand)))
502
+ return true ;
500
503
}
501
504
502
505
return false ;
Original file line number Diff line number Diff line change 1
- // RUN: %target-run-simple-swift(-Xfrontend -sil-verify-all) | %FileCheck %s
1
+ // RUN: %target-run-simple-swift(-Xfrontend -sil-verify-all)
2
2
3
3
// REQUIRES: executable_test
4
4
5
- // CHECK: MyInt: 5
6
- @inline ( never)
7
- func printInt( _ x: Int ) { print ( " MyInt: \( x) " ) }
5
+ import StdlibUnittest
6
+
7
+ defer { runAllTests ( ) }
8
+
9
+ var Tests = TestSuite ( " MoveOnlyTests " )
8
10
9
11
@_moveOnly
10
12
struct FD {
11
- var i = 5
13
+ var a = LifetimeTracked ( 0 )
12
14
13
15
deinit {
14
- printInt ( i)
15
16
}
16
17
}
17
18
18
- func main( ) {
19
- let x = FD ( )
20
- let _ = x
19
+ Tests . test ( " simple deinit called once " ) {
20
+ do {
21
+ let s = FD ( )
22
+ }
23
+ expectEqual ( 0 , LifetimeTracked . instances)
21
24
}
22
25
23
- main ( )
26
+ Tests . test ( " ref element addr destroyed once " ) {
27
+ class CopyableKlass {
28
+ var fd = FD ( )
29
+ }
30
+
31
+ func assignCopyableKlass( _ x: CopyableKlass ) {
32
+ x. fd = FD ( )
33
+ }
34
+
35
+ do {
36
+ let x = CopyableKlass ( )
37
+ assignCopyableKlass ( x)
38
+ }
39
+ expectEqual ( 0 , LifetimeTracked . instances)
40
+ }
41
+
42
+ var global = FD ( )
43
+
44
+ Tests . test ( " global destroyed once " ) {
45
+ do {
46
+ global = FD ( )
47
+ }
48
+ expectEqual ( 0 , LifetimeTracked . instances)
49
+ }
Original file line number Diff line number Diff line change @@ -493,3 +493,29 @@ bb0(%0 : @guaranteed $ClassContainingMoveOnly):
493
493
%11 = tuple ()
494
494
return %11 : $()
495
495
}
496
+
497
+ // CHECK: sil [ossa] @test_global_addr_write_use : $@convention(thin) () -> () {
498
+ // CHECK: bb0
499
+ // CHECK-NEXT: // function_ref
500
+ // CHECK-NEXT: function_ref
501
+ // CHECK-NEXT: apply
502
+ // CHECK-NEXT: global_addr
503
+ // CHECK-NEXT: begin_access
504
+ // CHECK-NEXT: destroy_addr
505
+ // CHECK-NEXT: store
506
+ // CHECK-NEXT: end_access
507
+ // CHECK-NEXT: tuple ()
508
+ // CHECK-NEXT: return
509
+ // CHECK: } // end sil function 'test_global_addr_write_use'
510
+ sil [ossa] @test_global_addr_write_use : $@convention(thin) () -> () {
511
+ bb0:
512
+ %9 = function_ref @getNonTrivialStruct : $@convention(thin) () -> @owned NonTrivialStruct
513
+ %10 = apply %9() : $@convention(thin) () -> @owned NonTrivialStruct
514
+ %0 = global_addr @$s23moveonly_addresschecker9varGlobalAA16NonTrivialStructVvp : $*NonTrivialStruct
515
+ %1 = begin_access [modify] [dynamic] %0 : $*NonTrivialStruct
516
+ %2 = mark_must_check [assignable_but_not_consumable] %0 : $*NonTrivialStruct
517
+ store %10 to [assign] %2 : $*NonTrivialStruct
518
+ end_access %1 : $*NonTrivialStruct
519
+ %8 = tuple ()
520
+ return %8 : $()
521
+ }
You can’t perform that action at this time.
0 commit comments