File: init_static_globals.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 (305 lines) | stat: -rw-r--r-- 11,040 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
// RUN: %target-sil-opt -enable-sil-verify-all %s -initialize-static-globals | %FileCheck %s

// REQUIRES: swift_in_compiler

sil_stage canonical

import Builtin
import Swift
import SwiftShims

public struct TStruct {
  let x: Int32
  init(x: Int32)
}

struct Outer {
  let a: Int32
  let b: TStruct
  let c: Int32
}

let trivialglobal: TStruct

public class TClass {
  final let x: Int32
  init(x: Int32)
  deinit
}

struct GenericStruct<T> {
  var x: T
}

struct TwoFields {
  let a: Int32
  let b: Int32
}

let nontrivialglobal: TClass

// CHECK-LABEL: sil_global hidden [let] @$trivialglobal : $TStruct = {
// CHECK:  [[CONST:%.*]] = integer_literal $Builtin.Int32, 10
// CHECK:  [[INT:%.*]] = struct $Int32 ([[CONST]] : $Builtin.Int32)
// CHECK:  %initval = struct $TStruct ([[INT]] : $Int32)
sil_global hidden [let] @$trivialglobal : $TStruct
sil_global private @globalinit_trivialglobal_token : $Builtin.Word


// CHECK-LABEL: sil_global hidden [let] @$nontrivialglobal : $TClass{{$}}
sil_global hidden [let] @$nontrivialglobal : $TClass
sil_global private @globalinit_nontrivialglobal_token : $Builtin.Word

// CHECK-LABEL: sil_global hidden [let] @empty_global : $GenericStruct<()>{{$}}
sil_global hidden [let] @empty_global : $GenericStruct<()>
sil_global private @empty_global_token : $Builtin.Word

// CHECK: sil_global @go : $Outer = {
// CHECK-NEXT:   %0 = integer_literal $Builtin.Int32, 2
// CHECK-NEXT:   %1 = struct $Int32 (%0 : $Builtin.Int32)
// CHECK-NEXT:   %2 = struct $TStruct (%1 : $Int32)
// CHECK-NEXT:   %initval = struct $Outer (%1 : $Int32, %2 : $TStruct, %1 : $Int32)
// CHECK-NEXT: }
sil_global @go : $Outer
sil_global private @globalinit_token0 : $Builtin.Word

// CHECK-LABEL: sil_global [let] @g1 : $Int32{{$}}
sil_global [let] @g1 : $Int32
sil_global private @g1_token : $Builtin.Word

// CHECK-LABEL: sil_global [let] @g2 : $Int32{{$}}
sil_global [let] @g2 : $Int32
sil_global private @g2_token : $Builtin.Word

// CHECK-LABEL: sil_global [let] @g3 : $Optional<UnsafeMutablePointer<Int>>
sil_global [let] @g3 : $Optional<UnsafeMutablePointer<Int>>
sil_global private @g3_token : $Builtin.Word

// CHECK-LABEL: sil_global [let] @g4 : $Optional<UnsafeMutablePointer<Int>>
sil_global [let] @g4 : $Optional<UnsafeMutablePointer<Int>>
sil_global private @g4_token : $Builtin.Word

// CHECK-LABEL: sil_global [let] @g5 : $TwoFields = {
// CHECK-NEXT:    %0 = integer_literal $Builtin.Int32, 11
// CHECK-NEXT:    %1 = struct $Int32 (%0 : $Builtin.Int32)
// CHECK-NEXT:    %2 = integer_literal $Builtin.Int32, 10
// CHECK-NEXT:    %3 = struct $Int32 (%2 : $Builtin.Int32)
// CHECK-NEXT:    %initval = struct $TwoFields (%1 : $Int32, %3 : $Int32)
// CHECK-NEXT:  }
sil_global [let] @g5 : $TwoFields

sil_global [let] @g6 : $TwoFields
sil_global [let] @g7 : $TwoFields

// CHECK-LABEL: sil_global [let] @g8 : $UnsafePointer<Int32> = {
// CHECK-NEXT:    %0 = global_addr @g1 : $*Int32
// CHECK-NEXT:    %1 = address_to_pointer %0 : $*Int32 to $Builtin.RawPointer
// CHECK-NEXT:    %initval = struct $UnsafePointer<Int32> (%1 : $Builtin.RawPointer)
// CHECK-NEXT:  }
sil_global [let] @g8 : $UnsafePointer<Int32>

sil_global [let] @g9 : $TwoFields

sil @unknownfunc : $@convention(thin) () -> ()

// CHECK-LABEL: sil [global_init_once_fn] [ossa] @globalinit_trivialglobal_func :
// CHECK-NOT:     alloc_global
// CHECK-NOT:     store
// CHECK:       } // end sil function 'globalinit_trivialglobal_func'
sil [global_init_once_fn] [ossa] @globalinit_trivialglobal_func : $@convention(c) () -> () {
bb0:
  alloc_global @$trivialglobal
  %1 = global_addr @$trivialglobal : $*TStruct
  %2 = integer_literal $Builtin.Int32, 10
  %3 = struct $Int32 (%2 : $Builtin.Int32)
  %4 = struct $TStruct (%3 : $Int32)
  store %4 to [trivial] %1 : $*TStruct
  %6 = tuple ()
  return %6 : $()
}

// CHECK-LABEL: sil [global_init_once_fn] [ossa] @globalinit_nontrivialglobal_func :
// CHECK:         alloc_global
// CHECK:         store
// CHECK:       } // end sil function 'globalinit_nontrivialglobal_func'
sil [global_init_once_fn] [ossa] @globalinit_nontrivialglobal_func : $@convention(c) () -> () {
bb0:
  alloc_global @$nontrivialglobal
  %1 = global_addr @$nontrivialglobal : $*TClass
  %2 = integer_literal $Builtin.Int32, 10
  %3 = struct $Int32 (%2 : $Builtin.Int32)
  %4 = alloc_ref $TClass
  %5 = begin_borrow %4 : $TClass
  %6 = ref_element_addr %5 : $TClass, #TClass.x
  store %3 to [trivial] %6 : $*Int32
  end_borrow %5 : $TClass
  store %4 to [init] %1 : $*TClass
  %10 = tuple ()
  return %10 : $()
}

// Check that we don't crash on an initializer struct with an "undef" operand.

// CHECK-LABEL: sil [global_init_once_fn] [ossa] @globalinit_with_undef :
// CHECK:         alloc_global
// CHECK:         store
// CHECK:       } // end sil function 'globalinit_with_undef'
sil [global_init_once_fn] [ossa] @globalinit_with_undef : $@convention(c) () -> () {
bb0:
  alloc_global @empty_global
  %1 = global_addr @empty_global : $*GenericStruct<()>
  %2 = struct $GenericStruct<()> (undef : $())
  store %2 to [trivial] %1 : $*GenericStruct<()>
  %4 = tuple ()
  return %4 : $()
}

// CHECK-LABEL: sil [global_init_once_fn] @globalinit_nested_struct :
// CHECK-NOT:     alloc_global
// CHECK-NOT:     store
// CHECK:       } // end sil function 'globalinit_nested_struct'
sil [global_init_once_fn] @globalinit_nested_struct : $@convention(c) () -> () {
bb0:
  alloc_global @go
  %0 = global_addr @go : $*Outer
  %1 = integer_literal $Builtin.Int32, 2
  %2 = struct $Int32 (%1 : $Builtin.Int32)
  %3 = struct $TStruct (%2 : $Int32)
  %4 = struct $Outer (%2 : $Int32, %3 : $TStruct, %2 : $Int32)
  store %4 to %0 : $*Outer
  %r = tuple ()
  return %r : $()
}

// CHECK-LABEL: sil [global_init_once_fn] @globalinit_mismatching_global :
// CHECK:         alloc_global
// CHECK:         store
// CHECK:       } // end sil function 'globalinit_mismatching_global'
sil [global_init_once_fn] @globalinit_mismatching_global : $@convention(c) () -> () {
bb0:
  alloc_global @g1
  %1 = global_addr @g2 : $*Int32
  %2 = integer_literal $Builtin.Int32, 10
  %3 = struct $Int32 (%2 : $Builtin.Int32)
  store %3 to %1 : $*Int32
  %6 = tuple ()
  return %6 : $()
}

// CHECK-LABEL: sil [global_init_once_fn] [ossa] @globalinit_enum :
// CHECK-NOT:     alloc_global
// CHECK-NOT:     store
// CHECK:       } // end sil function 'globalinit_enum'
sil [global_init_once_fn] [ossa] @globalinit_enum : $@convention(c) () -> () {
bb0:
  alloc_global @g3
  %2 = global_addr @g3 : $*Optional<UnsafeMutablePointer<Int>>
  %3 = enum $Optional<UnsafeMutablePointer<Int>>, #Optional.none!enumelt
  store %3 to [trivial] %2 : $*Optional<UnsafeMutablePointer<Int>>
  %5 = tuple ()
  return %5 : $()
}

// CHECK-LABEL: sil [global_init_once_fn] [ossa] @globalinit_enum_inttoptr :
// CHECK-NOT:     alloc_global
// CHECK-NOT:     store
// CHECK:       } // end sil function 'globalinit_enum_inttoptr'
sil [global_init_once_fn] [ossa] @globalinit_enum_inttoptr : $@convention(c) () -> () {
bb0:
  alloc_global @g4
  %2 = global_addr @g4 : $*Optional<UnsafeMutablePointer<Int>>
  %4 = integer_literal $Builtin.Word, 1111638594
  %5 = builtin "inttoptr_Word"(%4 : $Builtin.Word) : $Builtin.RawPointer
  %6 = struct $UnsafeMutablePointer<Int> (%5 : $Builtin.RawPointer)
  %7 = enum $Optional<UnsafeMutablePointer<Int>>, #Optional.some!enumelt, %6 : $UnsafeMutablePointer<Int>
  store %7 to [trivial] %2 : $*Optional<UnsafeMutablePointer<Int>>
  %10 = tuple ()
  return %10 : $()
}

// CHECK-LABEL: sil [global_init_once_fn] [ossa] @globalinit_separate_stores :
// CHECK-NOT:     alloc_global
// CHECK-NOT:     store
// CHECK:       } // end sil function 'globalinit_separate_stores'
sil [global_init_once_fn] [ossa] @globalinit_separate_stores : $@convention(c) () -> () {
bb0:
  alloc_global @g5
  %1 = global_addr @g5 : $*TwoFields
  %2 = integer_literal $Builtin.Int32, 10
  %3 = struct $Int32 (%2 : $Builtin.Int32)
  %4 = struct_element_addr %1 : $*TwoFields, #TwoFields.b
  store %3 to [trivial] %4 : $*Int32
  %6 = integer_literal $Builtin.Int32, 11
  %7 = struct $Int32 (%6 : $Builtin.Int32)
  %8 = struct_element_addr %1 : $*TwoFields, #TwoFields.a
  store %7 to [trivial] %8 : $*Int32
  %10 = tuple ()
  return %10 : $()
}

// CHECK-LABEL: sil [global_init_once_fn] [ossa] @merge_stores_but_no_global_init :
// CHECK:         [[GA:%.*]] = global_addr @g9 : $*TwoFields
// CHECK:         [[L10:%.*]] = integer_literal $Builtin.Int32, 10
// CHECK:         [[I10:%.*]] = struct $Int32 ([[L10]] : $Builtin.Int32)
// CHECK:         [[L11:%.*]] = integer_literal $Builtin.Int32, 11
// CHECK:         [[I11:%.*]] = struct $Int32 ([[L11]] : $Builtin.Int32)
// CHECK:         [[TF:%.*]] = struct $TwoFields ([[I11]] : $Int32, [[I10]] : $Int32)
// CHECK:         store [[TF]] to [trivial] [[GA]]
// CHECK:         function_ref
// CHECK:       } // end sil function 'merge_stores_but_no_global_init'
sil [global_init_once_fn] [ossa] @merge_stores_but_no_global_init : $@convention(c) () -> () {
bb0:
  alloc_global @g9
  %1 = global_addr @g9 : $*TwoFields
  %2 = integer_literal $Builtin.Int32, 10
  %3 = struct $Int32 (%2 : $Builtin.Int32)
  %4 = struct_element_addr %1 : $*TwoFields, #TwoFields.b
  store %3 to [trivial] %4 : $*Int32
  %6 = integer_literal $Builtin.Int32, 11
  %7 = struct $Int32 (%6 : $Builtin.Int32)
  %8 = struct_element_addr %1 : $*TwoFields, #TwoFields.a
  store %7 to [trivial] %8 : $*Int32
  %f = function_ref @unknownfunc : $@convention(thin) () -> ()
  %a = apply %f() : $@convention(thin) () -> ()
  %10 = tuple ()
  return %10 : $()
}

// CHECK-LABEL: sil [global_init_once_fn] [ossa] @globalinit_wrong_separate_stores :
// CHECK:         alloc_global
// CHECK:         store
// CHECK:         store
// CHECK:       } // end sil function 'globalinit_wrong_separate_stores'
sil [global_init_once_fn] [ossa] @globalinit_wrong_separate_stores : $@convention(c) () -> () {
bb0:
  alloc_global @g5
  %1 = global_addr @g5 : $*TwoFields
  %2 = integer_literal $Builtin.Int32, 10
  %3 = struct $Int32 (%2 : $Builtin.Int32)
  %4 = struct_element_addr %1 : $*TwoFields, #TwoFields.b
  store %3 to [trivial] %4 : $*Int32
  %6 = integer_literal $Builtin.Int32, 11
  %7 = struct $Int32 (%6 : $Builtin.Int32)
  store %7 to [trivial] %4 : $*Int32
  %10 = tuple ()
  return %10 : $()
}

// CHECK-LABEL: sil [global_init_once_fn] [ossa] @globalinit_pointer_to_other_global :
// CHECK-NOT:     alloc_global
// CHECK-NOT:     store
// CHECK:       } // end sil function 'globalinit_pointer_to_other_global'
sil [global_init_once_fn] [ossa] @globalinit_pointer_to_other_global : $@convention(c) (Builtin.RawPointer) -> () {
bb0(%0 : $Builtin.RawPointer):
  alloc_global @g8
  %2 = global_addr @g8 : $*UnsafePointer<Int32>
  %3 = global_addr @g1 : $*Int32
  %4 = begin_access [read] [dynamic] %3 : $*Int32
  %5 = address_to_pointer %4 : $*Int32 to $Builtin.RawPointer
  end_access %4 : $*Int32
  %7 = struct $UnsafePointer<Int32> (%5 : $Builtin.RawPointer)
  store %7 to [trivial] %2 : $*UnsafePointer<Int32>
  %8 = tuple ()
  return %8 : $()
}