forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefinite_init_crashes.sil
133 lines (104 loc) · 4.23 KB
/
definite_init_crashes.sil
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
// RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -enable-sil-verify-all %s -definite-init | %FileCheck %s
// These are all regression tests to ensure that the memory promotion pass
// doesn't crash.
import Builtin
import Swift
// Mixed combination of aggregate load/stores and elements.
struct Triple {
var a, b, c : Int
}
// CHECK-LABEL: sil @TripleTest
sil @TripleTest : $@convention(method) (Int, @inout Triple) -> Triple {
bb0(%0 : $Int, %1 : $*Triple):
%4 = alloc_box $<τ_0_0> { var τ_0_0 } <Triple>
%4a = project_box %4 : $<τ_0_0> { var τ_0_0 } <Triple>, 0
%5 = load %1 : $*Triple
store %5 to %4a : $*Triple
%8 = struct_element_addr %4a : $*Triple, #Triple.b
store %0 to %8 : $*Int
%10 = load %4a : $*Triple
strong_release %4 : $<τ_0_0> { var τ_0_0 } <Triple>
return %10 : $Triple
}
struct Single {
var a : Int
}
// CHECK-LABEL: sil @SingleTest
sil @SingleTest : $@convention(method) (@inout Single, Int) -> Single {
bb0(%0 : $*Single, %1 : $Int):
%4 = alloc_box $<τ_0_0> { var τ_0_0 } <Single>
%4a = project_box %4 : $<τ_0_0> { var τ_0_0 } <Single>, 0
%5 = load %0 : $*Single
store %5 to %4a : $*Single
%8 = struct_element_addr %4a : $*Single, #Single.a
store %1 to %8 : $*Int
%10 = load %4a : $*Single
strong_release %4 : $<τ_0_0> { var τ_0_0 } <Single>
return %10 : $Single
}
class SomeClass {}
enum SomeUnion {
case x(Int)
case y(SomeClass)
}
sil @getSomeClass : $@convention(thin) (@thick SomeClass.Type) -> @owned SomeClass
sil @getSomeUnion : $@convention(thin) (@owned SomeClass, @thin SomeUnion.Type) -> @owned SomeUnion
// CHECK-LABEL: sil @test_union_release
sil @test_union_release : $@convention(thin) () -> () {
bb0:
%0 = tuple ()
%1 = alloc_box $<τ_0_0> { var τ_0_0 } <SomeUnion> // users: %9, %8
%1a = project_box %1 : $<τ_0_0> { var τ_0_0 } <SomeUnion>, 0
%2 = function_ref @getSomeUnion : $@convention(thin) (@owned SomeClass, @thin SomeUnion.Type) -> @owned SomeUnion // user: %7
%3 = metatype $@thin SomeUnion.Type // user: %7
%4 = function_ref @getSomeClass : $@convention(thin) (@thick SomeClass.Type) -> @owned SomeClass // user: %6
%5 = metatype $@thick SomeClass.Type // user: %6
%6 = apply %4(%5) : $@convention(thin) (@thick SomeClass.Type) -> @owned SomeClass // user: %7
%7 = apply %2(%6, %3) : $@convention(thin) (@owned SomeClass, @thin SomeUnion.Type) -> @owned SomeUnion // user: %8
assign %7 to %1a : $*SomeUnion
strong_release %1 : $<τ_0_0> { var τ_0_0 } <SomeUnion>
%10 = tuple () // user: %11
return %10 : $()
}
public protocol Proto {
}
public struct MyErrorType {}
public struct NonTrivial {
@sil_stored let ptr: Builtin.NativeObject
}
public struct AStruct {
@sil_stored public let name: NonTrivial
@sil_stored public let foobar: NonTrivial
@sil_stored public let protoType: Proto.Type
}
sil @mayThrow : $@convention(thin) () -> (NonTrivial, @error MyErrorType)
// CHECK-LABEL: sil @assign_of_non_primitive_object_element_type
sil @assign_of_non_primitive_object_element_type : $@convention(thin) (@thick Proto.Type) -> (@owned AStruct, @error MyErrorType) {
bb0(%0 : $@thick Proto.Type):
%3 = alloc_stack $AStruct
%4 = mark_uninitialized [rootself] %3 : $*AStruct
%7 = function_ref @mayThrow : $@convention(thin) () -> (NonTrivial, @error MyErrorType)
try_apply %7() : $@convention(thin) () -> (NonTrivial, @error MyErrorType), normal bb1, error bb3
bb1(%15 : $NonTrivial):
%16 = struct_element_addr %4 : $*AStruct, #AStruct.foobar
assign %15 to %16 : $*NonTrivial
try_apply %7() : $@convention(thin) () -> (NonTrivial, @error MyErrorType), normal bb2, error bb4
bb2(%26 : $NonTrivial):
%27 = struct_element_addr %4 : $*AStruct, #AStruct.name
assign %26 to %27 : $*NonTrivial
%29 = struct_element_addr %4 : $*AStruct, #AStruct.protoType
assign %0 to %29 : $*@thick Proto.Type
%31 = load %4 : $*AStruct
retain_value %31 : $AStruct
destroy_addr %4 : $*AStruct
dealloc_stack %3 : $*AStruct
return %31 : $AStruct
bb3(%36 : $MyErrorType):
br bb5(%36 : $MyErrorType)
bb4(%38 : $MyErrorType):
br bb5(%38 : $MyErrorType)
bb5(%40 : $MyErrorType):
destroy_addr %4 : $*AStruct
dealloc_stack %3 : $*AStruct
throw %40 : $MyErrorType
}