Debian Codegraph @

clang/test/CodeGenObjC/nontrivial-c-struct-property.m

raw
1 // RUN: %clang_cc1 -triple arm64-apple-ios11 -fobjc-arc -emit-llvm -o - %s | FileCheck %s
2 @interface SuperClass
3 @end
4
5 typedef struct {
6 id x;
7 } S0;
8
9 @interface C : SuperClass {
10 S0 _p1;
11 }
12 @property(nonatomic) S0 nonatomic;
13 @property S0 atomic0;
14 @property S0 p1;
15 -(S0)p1;
16 -(void)setP1:(S0)s0;
17 @end
18
19 @implementation C
20 -(S0)p1 {
21 return _p1;
22 }
23 -(void)setP1:(S0)s0 {
24 _p1 = s0;
25 }
26 @end
27
28 // CHECK: %[[STRUCT_S0:.*]] = type { ptr }
29
30 // Check that parameters of user-defined setters are destructed.
31
32 // CHECK-LABEL: define internal void @"\01-[C setP1:]"(
33 // CHECK: %[[S0:.*]] = alloca %[[STRUCT_S0]], align 8
34 // CHECK: call void @__copy_assignment_8_8_s0(ptr %{{.*}}, ptr %[[S0]])
35 // CHECK: call void @__destructor_8_s0(ptr %[[S0]])
36
37 // CHECK: define internal i64 @"\01-[C nonatomic]"(ptr noundef %[[SELF:.*]], {{.*}})
38 // CHECK: %[[RETVAL:.*]] = alloca %[[STRUCT_S0]], align 8
39 // CHECK: %[[SELF_ADDR:.*]] = alloca ptr, align 8
40 // CHECK: store ptr %[[SELF]], ptr %[[SELF_ADDR]], align 8
41 // CHECK: %[[V0:.*]] = load ptr, ptr %[[SELF_ADDR]], align 8
42 // CHECK: %[[IVAR:.*]] = load i32, ptr @"OBJC_IVAR_$_C._nonatomic", align 8
43 // CHECK: %[[IVAR_CONV:.*]] = sext i32 %[[IVAR]] to i64
44 // CHECK: %[[ADD_PTR:.*]] = getelementptr inbounds i8, ptr %[[V0]], i64 %[[IVAR_CONV]]
45 // CHECK: call void @__copy_constructor_8_8_s0(ptr %[[RETVAL]], ptr %[[ADD_PTR]])
46 // CHECK-NOT: call
47 // CHECK: ret i64
48
49 // CHECK: define internal void @"\01-[C setNonatomic:]"(ptr noundef %[[SELF:.*]], {{.*}}, i64 %[[NONATOMIC_COERCE:.*]])
50 // CHECK: %[[NONATOMIC:.*]] = alloca %[[STRUCT_S0]], align 8
51 // CHECK: %[[SELF_ADDR:.*]] = alloca ptr, align 8
52 // CHECK: %[[COERCE_DIVE:.*]] = getelementptr inbounds nuw %[[STRUCT_S0]], ptr %[[NONATOMIC]], i32 0, i32 0
53 // CHECK: %[[COERCE_VAL_IP:.*]] = inttoptr i64 %[[NONATOMIC_COERCE]] to ptr
54 // CHECK: store ptr %[[COERCE_VAL_IP]], ptr %[[COERCE_DIVE]], align 8
55 // CHECK: store ptr %[[SELF]], ptr %[[SELF_ADDR]], align 8
56 // CHECK: %[[V0:.*]] = load ptr, ptr %[[SELF_ADDR]], align 8
57 // CHECK: %[[IVAR:.*]] = load i32, ptr @"OBJC_IVAR_$_C._nonatomic", align 8
58 // CHECK: %[[IVAR_CONV:.*]] = sext i32 %[[IVAR]] to i64
59 // CHECK: %[[ADD_PTR:.*]] = getelementptr inbounds i8, ptr %[[V0]], i64 %[[IVAR_CONV]]
60 // CHECK: call void @__move_assignment_8_8_s0(ptr %[[ADD_PTR]], ptr %[[NONATOMIC]])
61 // CHECK-NOT: call
62 // CHECK: ret void
63
64 // CHECK-LABEL: define internal i64 @"\01-[C atomic0]"(
65 // CHECK: call void @objc_copyCppObjectAtomic({{.*}}, {{.*}}, ptr noundef @__copy_constructor_8_8_s0)
66 // CHECK-NOT: call
67 // CHECK: ret i64
68
69 // CHECK-LABEL: define internal void @"\01-[C setAtomic0:]"(
70 // CHECK: call void @objc_copyCppObjectAtomic({{.*}}, {{.*}}, ptr noundef @__move_assignment_8_8_s0)
71 // CHECK-NOT: call
72 // CHECK: ret void
73
74 // CHECK: define void @test0(ptr noundef %[[C:.*]], ptr noundef %[[A:.*]])
75 // CHECK: %[[C_ADDR:.*]] = alloca ptr, align 8
76 // CHECK: %[[A_ADDR:.*]] = alloca ptr, align 8
77 // CHECK: %[[AGG_TMP_ENSURED:.*]] = alloca %[[STRUCT_S0]], align 8
78 // CHECK: %[[AGG_TMP:.*]] = alloca %[[STRUCT_S0]], align 8
79 // CHECK: store ptr null, ptr %[[C_ADDR]], align 8
80 // CHECK: call void @llvm.objc.storeStrong(ptr %[[C_ADDR]], ptr %[[C]])
81 // CHECK: store ptr %[[A]], ptr %[[A_ADDR]], align 8
82 // CHECK: %[[V0:.*]] = load ptr, ptr %[[A_ADDR]], align 8
83 // CHECK: call void @__copy_constructor_8_8_s0(ptr %[[AGG_TMP_ENSURED]], ptr %[[V0]])
84 // CHECK: %[[V1:.*]] = load ptr, ptr %[[C_ADDR]], align 8
85 // CHECK: call void @__copy_constructor_8_8_s0(ptr %[[AGG_TMP]], ptr %[[AGG_TMP_ENSURED]])
86 // CHECK: %[[V2:.*]] = icmp eq ptr %[[V1]], null
87 // CHECK: br i1 %[[V2]], label %[[MSGSEND_NULL:.*]], label %[[MSGSEND_CALL:.*]]
88
89 // CHECK: [[MSGSEND_CALL]]:
90 // CHECK: %[[V3:.*]] = load ptr, ptr @OBJC_SELECTOR_REFERENCES_, align 8
91 // CHECK: %[[COERCE_DIVE:.*]] = getelementptr inbounds nuw %[[STRUCT_S0]], ptr %[[AGG_TMP]], i32 0, i32 0
92 // CHECK: %[[V4:.*]] = load ptr, ptr %[[COERCE_DIVE]], align 8
93 // CHECK: %[[COERCE_VAL_PI:.*]] = ptrtoint ptr %[[V4]] to i64
94 // CHECK: call void @objc_msgSend(ptr noundef %[[V1]], ptr noundef %[[V3]], i64 %[[COERCE_VAL_PI]])
95 // CHECK: br label %[[MSGSEND_CONT:.*]]
96
97 // CHECK: [[MSGSEND_NULL]]:
98 // CHECK: call void @__destructor_8_s0(ptr %[[AGG_TMP]])
99 // CHECK: br label %[[MSGSEND_CONT]]
100
101 // CHECK: [[MSGSEND_CONT]]:
102 // CHECK: call void @__destructor_8_s0(ptr %[[AGG_TMP_ENSURED]]
103 // CHECK: call void @llvm.objc.storeStrong(ptr %[[C_ADDR]], ptr null)
104 // CHECK: ret void
105
106 void test0(C *c, S0 *a) {
107 c.atomic0 = *a;
108 }