File: definite_init_moveonly_controlflowdep_init.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 (136 lines) | stat: -rw-r--r-- 5,632 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
// RUN: %target-sil-opt -module-name definite_init_moveonly_controlflowdep_init -enable-sil-verify-all -definite-init %s | %FileCheck %s
// RUN: %target-sil-opt -module-name definite_init_moveonly_controlflowdep_init -enable-sil-verify-all -definite-init -raw-sil-inst-lowering -sil-move-only-checker -verify %s

// Test that we properly handle both escaping and non-escaping variants.

@_moveOnly
struct S {}

sil @borrowVal : $@convention(thin) (@guaranteed S) -> ()
sil @consumeVal : $@convention(thin) (@owned S) -> ()
sil @getVal : $@convention(thin) () -> @owned S
sil @closureTakeVal : $@convention(thin) (@guaranteed { let S }) -> ()

// CHECK-LABEL: sil hidden [ossa] @letControlFlowDependentInitializationNoEscape : $@convention(thin) () -> () {
// CHECK: [[STACK:%.*]] = alloc_stack
// CHECK: [[MU:%.*]] = mark_uninitialized [var] [[STACK]]
// CHECK: [[MARK:%.*]] = mark_unresolved_non_copyable_value [consumable_and_assignable] [[MU]]
// CHECK: cond_br undef, [[LHS_BB:bb[0-9]+]], [[RHS_BB:bb[0-9]+]]
//
// CHECK: [[LHS_BB]]:
// CHECK:   assign {{%.*}} to [init] [[MARK]]
// CHECK:   br [[CONT_BB:bb[0-9]+]]
//
// CHECK: [[RHS_BB]]:
// CHECK:   assign {{%.*}} to [init] [[MARK]]
// CHECK:   br [[CONT_BB]]
//
// CHECK: [[CONT_BB]]:
// CHECK:   [[LOAD:%.*]] = load [copy] [[MARK]]
// CHECK:   apply {{%.*}}([[LOAD]])
// CHECK:   destroy_value [[LOAD]]
// CHECK:   [[LOAD:%.*]] = load [take] [[MARK]]
// CHECK:   apply {{%.*}}([[LOAD]])
// CHECK:   destroy_addr [[MARK]]
// CHECK:   dealloc_stack [[STACK]]
// CHECK: } // end sil function 'letControlFlowDependentInitializationNoEscape'
sil hidden [ossa] @letControlFlowDependentInitializationNoEscape : $@convention(thin) () -> () {
bb0:
  %0 = alloc_stack $S, let, name "s"
  %1 = mark_uninitialized [var] %0 : $*S
  %2 = mark_unresolved_non_copyable_value [consumable_and_assignable] %1 : $*S
  cond_br undef, bb1, bb2

bb1:
  %8 = function_ref @getVal : $@convention(thin) () -> @owned S
  %9 = apply %8() : $@convention(thin) () -> @owned S
  assign %9 to %2 : $*S
  br bb3

bb2:
  %13 = function_ref @getVal : $@convention(thin) () -> @owned S
  %14 = apply %13() : $@convention(thin) () -> @owned S
  assign %14 to %2 : $*S
  br bb3

bb3:
  %17 = load [copy] %2 : $*S
  %18 = function_ref @borrowVal : $@convention(thin) (@guaranteed S) -> ()
  %19 = apply %18(%17) : $@convention(thin) (@guaranteed S) -> ()
  destroy_value %17 : $S
  %21 = load [take] %2 : $*S
  %22 = function_ref @consumeVal : $@convention(thin) (@owned S) -> ()
  %23 = apply %22(%21) : $@convention(thin) (@owned S) -> ()
  destroy_addr %2 : $*S
  dealloc_stack %0 : $*S
  %26 = tuple ()
  return %26 : $()
}

// CHECK-LABEL: sil hidden [ossa] @letControlFlowDependentInitializationEscape : $@convention(thin) () -> () {
// CHECK: [[BOX:%.*]] = alloc_box
// CHECK: [[MU:%.*]] = mark_uninitialized [var] [[BOX]]
// CHECK: [[PROJECT:%.*]] = project_box [[MU]]
// CHECK: cond_br undef, [[LHS_BB:bb[0-9]+]], [[RHS_BB:bb[0-9]+]]
//
// CHECK: [[LHS_BB]]:
// CHECK:   [[MARK:%.*]] = mark_unresolved_non_copyable_value [initable_but_not_consumable] [[PROJECT]]
// CHECK:   assign {{%.*}} to [init] [[MARK]]
// CHECK:   br [[CONT_BB:bb[0-9]+]]
//
// CHECK: [[RHS_BB]]:
// CHECK:   [[MARK:%.*]] = mark_unresolved_non_copyable_value [initable_but_not_consumable] [[PROJECT]]
// CHECK:   assign {{%.*}} to [init] [[MARK]]
// CHECK:   br [[CONT_BB]]
//
// CHECK: [[CONT_BB]]:
// CHECK:   [[MARK:%.*]] = mark_unresolved_non_copyable_value [no_consume_or_assign] [[PROJECT]]
// CHECK:   [[LOAD:%.*]] = load [copy] [[MARK]]
// CHECK:   apply {{%.*}}([[LOAD]])
// CHECK:   destroy_value [[LOAD]]
//
// The checker will properly error and say that this is illegal on a let.
// CHECK:   [[MARK:%.*]] = mark_unresolved_non_copyable_value [assignable_but_not_consumable] [[PROJECT]]
// CHECK:   [[LOAD:%.*]] = load [take] [[MARK]]
// CHECK:   apply {{%.*}}([[LOAD]])
sil hidden [ossa] @letControlFlowDependentInitializationEscape : $@convention(thin) () -> () {
bb0:
  %1 = alloc_box ${ let S }, let, name "s"
  %2 = mark_uninitialized [var] %1 : ${ let S }
  %3 = project_box %2 : ${ let S }, 0
  cond_br undef, bb1, bb2

bb1:
  %9 = function_ref @getVal : $@convention(thin) () -> @owned S
  %10 = apply %9() : $@convention(thin) () -> @owned S
  %11 = mark_unresolved_non_copyable_value [assignable_but_not_consumable] %3 : $*S
  assign %10 to %11 : $*S
  br bb3

bb2:
  %15 = function_ref @getVal : $@convention(thin) () -> @owned S
  %16 = apply %15() : $@convention(thin) () -> @owned S
  %17 = mark_unresolved_non_copyable_value [assignable_but_not_consumable] %3 : $*S
  assign %16 to %17 : $*S
  br bb3

bb3:
  %20 = mark_unresolved_non_copyable_value [no_consume_or_assign] %3 : $*S
  %21 = load [copy] %20 : $*S
  %22 = function_ref @borrowVal : $@convention(thin) (@guaranteed S) -> ()
  %23 = apply %22(%21) : $@convention(thin) (@guaranteed S) -> ()
  destroy_value %21 : $S
  %25 = mark_unresolved_non_copyable_value [assignable_but_not_consumable] %3 : $*S
  // expected-error @-1 {{noncopyable 's' cannot be consumed when captured by an escaping closure}}
  %26 = load [take] %25 : $*S
  %27 = function_ref @consumeVal : $@convention(thin) (@owned S) -> ()
  %28 = apply %27(%26) : $@convention(thin) (@owned S) -> ()
  %29 = function_ref @closureTakeVal : $@convention(thin) (@guaranteed { let S }) -> ()
  %30 = copy_value %2 : ${ let S }
  mark_function_escape %3 : $*S
  %32 = partial_apply [callee_guaranteed] %29(%30) : $@convention(thin) (@guaranteed { let S }) -> ()
  destroy_value %32 : $@callee_guaranteed () -> ()
  destroy_value %2 : ${ let S }
  %37 = tuple ()
  return %37 : $()
}