Skip to content

Commit 82afc7c

Browse files
committed
Add test: diagnostic_passes_todo.sil
1 parent 064d37f commit 82afc7c

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// RUN: %target-sil-opt -test-runner %s \
2+
// RUN: -diagnostics -sil-verify-all \
3+
// RUN: -enable-experimental-feature LifetimeDependence \
4+
// RUN: -enable-experimental-feature LifetimeDependenceDiagnoseTrivial \
5+
// RUN: 2>&1 | %FileCheck %s
6+
7+
// REQUIRES: swift_feature_LifetimeDependence
8+
// REQUIRES: swift_feature_LifetimeDependenceDiagnoseTrivial
9+
10+
// Test SIL expected from SILGen output. Run all diagnostic passes which includes lifetime dependence handling.
11+
// These tests are not fully implemented.
12+
13+
sil_stage raw
14+
15+
import Builtin
16+
import Swift
17+
import SwiftShims
18+
19+
struct Owner {}
20+
struct NE: ~Escapable {}
21+
struct OtherNE: ~Escapable {}
22+
23+
sil @getNE : $@convention(c) (@in_guaranteed Owner) -> @lifetime(borrow 0) @autoreleased NE
24+
sil @copyNE : $@convention(c) (NE, @lifetime(copy 0) @inout NE) -> ()
25+
sil @makeOwner : $@convention(c) () -> Owner
26+
27+
// TODO: Diagnostics should report that end of the 'owner' variable scope end before 'v1' is destroyed.
28+
//
29+
// CHECK-LABEL: sil [ossa] @testInoutReassign_fail : $@convention(thin) () -> () {
30+
sil [ossa] @testInoutReassign_fail : $@convention(thin) () -> () {
31+
bb0:
32+
%0 = function_ref @makeOwner : $@convention(c) () -> Owner // user: %1
33+
%1 = apply %0() : $@convention(c) () -> Owner
34+
%2 = move_value [var_decl] %1 : $Owner
35+
debug_value %2 : $Owner, let, name "owner"
36+
37+
// Declare v1: NE
38+
%8 = alloc_box ${ var NE }, var, name "v1"
39+
%9 = begin_borrow [var_decl] %8 : ${ var NE }
40+
%10 = project_box %9 : ${ var NE }, 0
41+
42+
// v1 = owner.ne
43+
%11 = alloc_stack $Owner
44+
store %2 to [trivial] %11 : $*Owner
45+
%13 = function_ref @getNE : $@convention(c) (@in_guaranteed Owner) -> @lifetime(borrow 0) @autoreleased NE
46+
%14 = apply %13(%11) : $@convention(c) (@in_guaranteed Owner) -> @lifetime(borrow 0) @autoreleased NE
47+
dealloc_stack %11 : $*Owner
48+
store %14 to [init] %10 : $*NE
49+
50+
// v2 = owner.ne
51+
%17 = alloc_stack $Owner
52+
store %2 to [trivial] %17 : $*Owner
53+
%22 = apply %13(%17) : $@convention(c) (@in_guaranteed Owner) -> @lifetime(borrow 0) @autoreleased NE
54+
dealloc_stack %17 : $*Owner
55+
%25 = move_value [var_decl] %22 : $NE
56+
debug_value %25 : $NE, let, name "v2"
57+
58+
// copyView(v2, &v1)
59+
%81 = begin_borrow %25 : $NE
60+
%82 = begin_access [modify] [unknown] %10 : $*NE
61+
%83 = function_ref @copyNE : $@convention(c) (NE, @lifetime(copy 0) @inout NE) -> ()
62+
%84 = apply %83(%81, %82) : $@convention(c) (NE, @lifetime(copy 0) @inout NE) -> ()
63+
end_access %82 : $*NE
64+
end_borrow %81 : $NE
65+
66+
// destroy v2
67+
destroy_value %25 : $NE
68+
69+
// Owner does not cover v1.
70+
extend_lifetime %2 : $Owner
71+
72+
// destroy v1
73+
end_borrow %9 : ${ var NE }
74+
destroy_value %8 : ${ var NE }
75+
76+
%93 = tuple ()
77+
return %93 : $()
78+
}

0 commit comments

Comments
 (0)