xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenObjC/arc-property.m (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-arc -emit-llvm %s -o - | FileCheck %s
2f4a2713aSLionel Sambuc
3f4a2713aSLionel Sambuc// rdar://problem/10290317
4f4a2713aSLionel Sambuc@interface Test0
5f4a2713aSLionel Sambuc- (void) setValue: (id) x;
6f4a2713aSLionel Sambuc@end
7f4a2713aSLionel Sambucvoid test0(Test0 *t0, id value) {
8f4a2713aSLionel Sambuc  t0.value = value;
9f4a2713aSLionel Sambuc}
10f4a2713aSLionel Sambuc// CHECK-LABEL: define void @test0(
11f4a2713aSLionel Sambuc// CHECK: call void @objc_storeStrong
12f4a2713aSLionel Sambuc// CHECK: call void @objc_storeStrong
13f4a2713aSLionel Sambuc// CHECK: @objc_msgSend
14f4a2713aSLionel Sambuc// CHECK: call void @objc_storeStrong(
15f4a2713aSLionel Sambuc// CHECK: call void @objc_storeStrong(
16f4a2713aSLionel Sambuc
17f4a2713aSLionel Sambucstruct S1 { Class isa; };
18f4a2713aSLionel Sambuc@interface Test1
19f4a2713aSLionel Sambuc@property (nonatomic, strong) __attribute__((NSObject)) struct S1 *pointer;
20f4a2713aSLionel Sambuc@end
21f4a2713aSLionel Sambuc@implementation Test1
22f4a2713aSLionel Sambuc@synthesize pointer;
23f4a2713aSLionel Sambuc@end
24f4a2713aSLionel Sambuc//   The getter should be a simple load.
25f4a2713aSLionel Sambuc// CHECK:    define internal [[S1:%.*]]* @"\01-[Test1 pointer]"(
26f4a2713aSLionel Sambuc// CHECK:      [[OFFSET:%.*]] = load i64* @"OBJC_IVAR_$_Test1.pointer"
27f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST1:%.*]]* {{%.*}} to i8*
28f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8* [[T0]], i64 [[OFFSET]]
29f4a2713aSLionel Sambuc// CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to [[S1]]**
30f4a2713aSLionel Sambuc// CHECK-NEXT: [[T3:%.*]] = load [[S1]]** [[T2]], align 8
31f4a2713aSLionel Sambuc// CHECK-NEXT: ret [[S1]]* [[T3]]
32f4a2713aSLionel Sambuc
33f4a2713aSLionel Sambuc//   The setter should be using objc_setProperty.
34f4a2713aSLionel Sambuc// CHECK:    define internal void @"\01-[Test1 setPointer:]"(
35f4a2713aSLionel Sambuc// CHECK:      [[T0:%.*]] = bitcast [[TEST1]]* {{%.*}} to i8*
36f4a2713aSLionel Sambuc// CHECK-NEXT: [[OFFSET:%.*]] = load i64* @"OBJC_IVAR_$_Test1.pointer"
37f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = load [[S1]]** {{%.*}}
38f4a2713aSLionel Sambuc// CHECK-NEXT: [[T2:%.*]] = bitcast [[S1]]* [[T1]] to i8*
39f4a2713aSLionel Sambuc// CHECK-NEXT: call void @objc_setProperty(i8* [[T0]], i8* {{%.*}}, i64 [[OFFSET]], i8* [[T2]], i1 zeroext false, i1 zeroext false)
40f4a2713aSLionel Sambuc// CHECK-NEXT: ret void
41f4a2713aSLionel Sambuc
42f4a2713aSLionel Sambuc
43f4a2713aSLionel Sambuc// rdar://problem/12039404
44f4a2713aSLionel Sambuc@interface Test2 {
45f4a2713aSLionel Sambuc@private
46f4a2713aSLionel Sambuc  Class _theClass;
47f4a2713aSLionel Sambuc}
48f4a2713aSLionel Sambuc@property (copy) Class theClass;
49f4a2713aSLionel Sambuc@end
50f4a2713aSLionel Sambuc
51f4a2713aSLionel Sambucstatic Class theGlobalClass;
52f4a2713aSLionel Sambuc@implementation Test2
53f4a2713aSLionel Sambuc@synthesize theClass = _theClass;
54f4a2713aSLionel Sambuc- (void) test {
55f4a2713aSLionel Sambuc  _theClass = theGlobalClass;
56f4a2713aSLionel Sambuc}
57f4a2713aSLionel Sambuc@end
58f4a2713aSLionel Sambuc// CHECK:    define internal void @"\01-[Test2 test]"(
59f4a2713aSLionel Sambuc// CHECK:      [[T0:%.*]] = load i8** @theGlobalClass, align 8
60f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = load [[TEST2:%.*]]**
61f4a2713aSLionel Sambuc// CHECK-NEXT: [[OFFSET:%.*]] = load i64* @"OBJC_IVAR_$_Test2._theClass"
62f4a2713aSLionel Sambuc// CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST2]]* [[T1]] to i8*
63f4a2713aSLionel Sambuc// CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i8* [[T2]], i64 [[OFFSET]]
64f4a2713aSLionel Sambuc// CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to i8**
65f4a2713aSLionel Sambuc// CHECK-NEXT: call void @objc_storeStrong(i8** [[T4]], i8* [[T0]]) [[NUW:#[0-9]+]]
66f4a2713aSLionel Sambuc// CHECK-NEXT: ret void
67f4a2713aSLionel Sambuc
68f4a2713aSLionel Sambuc// CHECK:    define internal i8* @"\01-[Test2 theClass]"(
69f4a2713aSLionel Sambuc// CHECK:      [[OFFSET:%.*]] = load i64* @"OBJC_IVAR_$_Test2._theClass"
70*0a6a1f1dSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = tail call i8* @objc_getProperty(i8* {{.*}}, i8* {{.*}}, i64 [[OFFSET]], i1 zeroext true)
71f4a2713aSLionel Sambuc// CHECK-NEXT: ret i8* [[T0]]
72f4a2713aSLionel Sambuc
73f4a2713aSLionel Sambuc// CHECK:    define internal void @"\01-[Test2 setTheClass:]"(
74f4a2713aSLionel Sambuc// CHECK:      [[T0:%.*]] = bitcast [[TEST2]]* {{%.*}} to i8*
75f4a2713aSLionel Sambuc// CHECK-NEXT: [[OFFSET:%.*]] = load i64* @"OBJC_IVAR_$_Test2._theClass"
76f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = load i8** {{%.*}}
77f4a2713aSLionel Sambuc// CHECK-NEXT: call void @objc_setProperty(i8* [[T0]], i8* {{%.*}}, i64 [[OFFSET]], i8* [[T1]], i1 zeroext true, i1 zeroext true)
78f4a2713aSLionel Sambuc// CHECK-NEXT: ret void
79f4a2713aSLionel Sambuc
80f4a2713aSLionel Sambuc// CHECK:    define internal void @"\01-[Test2 .cxx_destruct]"(
81f4a2713aSLionel Sambuc// CHECK:      [[T0:%.*]] = load [[TEST2]]**
82f4a2713aSLionel Sambuc// CHECK-NEXT: [[OFFSET:%.*]] = load i64* @"OBJC_IVAR_$_Test2._theClass"
83f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST2]]* [[T0]] to i8*
84f4a2713aSLionel Sambuc// CHECK-NEXT: [[T2:%.*]] = getelementptr inbounds i8* [[T1]], i64 [[OFFSET]]
85f4a2713aSLionel Sambuc// CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to i8**
86f4a2713aSLionel Sambuc// CHECK-NEXT: call void @objc_storeStrong(i8** [[T3]], i8* null) [[NUW]]
87f4a2713aSLionel Sambuc// CHECK-NEXT: ret void
88f4a2713aSLionel Sambuc
89f4a2713aSLionel Sambuc// rdar://13115896
90f4a2713aSLionel Sambuc@interface Test3
91f4a2713aSLionel Sambuc@property id copyMachine;
92f4a2713aSLionel Sambuc@end
93f4a2713aSLionel Sambuc
94f4a2713aSLionel Sambucvoid test3(Test3 *t) {
95f4a2713aSLionel Sambuc  id x = t.copyMachine;
96f4a2713aSLionel Sambuc  x = [t copyMachine];
97f4a2713aSLionel Sambuc}
98f4a2713aSLionel Sambuc// CHECK:    define void @test3([[TEST3:%.*]]*
99f4a2713aSLionel Sambuc//   Prologue.
100f4a2713aSLionel Sambuc// CHECK:      [[T:%.*]] = alloca [[TEST3]]*,
101f4a2713aSLionel Sambuc// CHECK-NEXT: [[X:%.*]] = alloca i8*,
102f4a2713aSLionel Sambuc//   Property access.
103f4a2713aSLionel Sambuc// CHECK:      [[T0:%.*]] = load [[TEST3]]** [[T]],
104*0a6a1f1dSLionel Sambuc// CHECK-NEXT: [[SEL:%.*]] = load i8** @OBJC_SELECTOR_REFERENCES
105f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST3]]* [[T0]] to i8*
106f4a2713aSLionel Sambuc// CHECK-NEXT: [[T2:%.*]] = call i8* bitcast ({{.*}} @objc_msgSend to {{.*}})(i8* [[T1]], i8* [[SEL]])
107f4a2713aSLionel Sambuc// CHECK-NEXT: store i8* [[T2]], i8** [[X]],
108f4a2713aSLionel Sambuc//   Message send.
109f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = load [[TEST3]]** [[T]],
110*0a6a1f1dSLionel Sambuc// CHECK-NEXT: [[SEL:%.*]] = load i8** @OBJC_SELECTOR_REFERENCES
111f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST3]]* [[T0]] to i8*
112f4a2713aSLionel Sambuc// CHECK-NEXT: [[T2:%.*]] = call i8* bitcast ({{.*}} @objc_msgSend to {{.*}})(i8* [[T1]], i8* [[SEL]])
113f4a2713aSLionel Sambuc// CHECK-NEXT: [[T3:%.*]] = load i8** [[X]],
114f4a2713aSLionel Sambuc// CHECK-NEXT: store i8* [[T2]], i8** [[X]],
115f4a2713aSLionel Sambuc// CHECK-NEXT: call void @objc_release(i8* [[T3]])
116f4a2713aSLionel Sambuc//   Epilogue.
117f4a2713aSLionel Sambuc// CHECK-NEXT: call void @objc_storeStrong(i8** [[X]], i8* null)
118f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST3]]** [[T]] to i8**
119f4a2713aSLionel Sambuc// CHECK-NEXT: call void @objc_storeStrong(i8** [[T0]], i8* null)
120f4a2713aSLionel Sambuc// CHECK-NEXT: ret void
121f4a2713aSLionel Sambuc
122f4a2713aSLionel Sambuc@implementation Test3
123f4a2713aSLionel Sambuc- (id) copyMachine {
124f4a2713aSLionel Sambuc  extern id test3_helper(void);
125f4a2713aSLionel Sambuc  return test3_helper();
126f4a2713aSLionel Sambuc}
127f4a2713aSLionel Sambuc// CHECK:    define internal i8* @"\01-[Test3 copyMachine]"(
128f4a2713aSLionel Sambuc// CHECK:      [[T0:%.*]] = call i8* @test3_helper()
129f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]])
130f4a2713aSLionel Sambuc// CHECK-NEXT: ret i8* [[T1]]
131f4a2713aSLionel Sambuc- (void) setCopyMachine: (id) x {}
132f4a2713aSLionel Sambuc@end
133f4a2713aSLionel Sambuc
134f4a2713aSLionel Sambuc// CHECK: attributes [[NUW]] = { nounwind }
135