forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass_resilience.swift
75 lines (57 loc) · 3.02 KB
/
class_resilience.swift
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
// RUN: %target-swift-frontend -I %S/../Inputs -enable-source-import -emit-ir -enable-resilience %s | FileCheck %s
// RUN: %target-swift-frontend -I %S/../Inputs -enable-source-import -emit-ir -enable-resilience -O %s
// CHECK: %Si = type <{ [[INT:i32|i64]] }>
import resilient_struct
import resilient_enum
// Concrete class with resilient stored property
public class MyRectangle {
public let p: Point
public let s: Size
public let color: Int
public init(p: Point, s: Size, color: Int) {
self.p = p
self.s = s
self.color = color
}
}
// Concrete class with non-fixed size stored property
public class ClassWithResilientLayout {
public let r: Rectangle
public let color: Int
public init(r: Rectangle, color: Int) {
self.r = r
self.color = color
}
}
// Enums with indirect payloads are fixed-size
public class ClassWithIndirectResilientEnum {
public let s: FunnyShape
public let color: Int
public init(s: FunnyShape, color: Int) {
self.s = s
self.color = color
}
}
// FIXME: This is bogus since we don't emit code to initialize the
// global ivar offsets yet.
// CHECK-LABEL: define {{i32|i64}} @_TFC16class_resilience11MyRectangleg5colorSi(%C16class_resilience11MyRectangle*)
// CHECK: [[OFFSET:%.*]] = load [[INT]], [[INT]]* @_TWvdvC16class_resilience11MyRectangle5colorSi
// CHECK-NEXT: [[PTR:%.*]] = bitcast %C16class_resilience11MyRectangle* %0 to i8*
// CHECK-NEXT: [[FIELD_ADDR:%.*]] = getelementptr inbounds i8, i8* [[PTR]], [[INT]] [[OFFSET]]
// CHECK-NEXT: [[FIELD_PTR:%.*]] = bitcast i8* [[FIELD_ADDR]] to %Si*
// CHECK-NEXT: [[FIELD_PAYLOAD:%.*]] = getelementptr inbounds %Si, %Si* [[FIELD_PTR]], i32 0, i32 0
// CHECK-NEXT: [[FIELD_VALUE:%.*]] = load [[INT]], [[INT]]* [[FIELD_PAYLOAD]]
// CHECK-NEXT: ret [[INT]] [[FIELD_VALUE]]
// CHECK-LABEL: define {{i32|i64}} @_TFC16class_resilience24ClassWithResilientLayoutg5colorSi(%C16class_resilience24ClassWithResilientLayout*)
// CHECK: [[OFFSET:%.*]] = load [[INT]], [[INT]]* @_TWvdvC16class_resilience24ClassWithResilientLayout5colorSi
// CHECK-NEXT: [[PTR:%.*]] = bitcast %C16class_resilience24ClassWithResilientLayout* %0 to i8*
// CHECK-NEXT: [[FIELD_ADDR:%.*]] = getelementptr inbounds i8, i8* [[PTR]], [[INT]] [[OFFSET]]
// CHECK-NEXT: [[FIELD_PTR:%.*]] = bitcast i8* [[FIELD_ADDR]] to %Si*
// CHECK-NEXT: [[FIELD_PAYLOAD:%.*]] = getelementptr inbounds %Si, %Si* %.color, i32 0, i32 0
// CHECK-NEXT: [[FIELD_VALUE:%.*]] = load [[INT]], [[INT]]* [[FIELD_PAYLOAD]]
// CHECK-NEXT: ret [[INT]] [[FIELD_VALUE]]
// CHECK-LABEL: define {{i32|i64}} @_TFC16class_resilience30ClassWithIndirectResilientEnumg5colorSi(%C16class_resilience30ClassWithIndirectResilientEnum*)
// CHECK: [[FIELD_PTR:%.*]] = getelementptr inbounds %C16class_resilience30ClassWithIndirectResilientEnum, %C16class_resilience30ClassWithIndirectResilientEnum* %0, i32 0, i32 2
// CHECK-NEXT: [[FIELD_PAYLOAD:%.*]] = getelementptr inbounds %Si, %Si* [[FIELD_PTR]], i32 0, i32 0
// CHECK-NEXT: [[FIELD_VALUE:%.*]] = load [[INT]], [[INT]]* [[FIELD_PAYLOAD]]
// CHECK-NEXT: ret [[INT]] [[FIELD_VALUE]]