1 // RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-apple-darwin10 -fobjc-arc -emit-llvm %s -o - | FileCheck %s
3 // rdar://problem/10290317
5 - (void) setValue: (id) x;
7 void test0(Test0 *t0, id value) {
10 // CHECK-LABEL: define{{.*}} void @test0(
11 // CHECK: call void @llvm.objc.storeStrong
12 // CHECK: call void @llvm.objc.storeStrong
13 // CHECK: @objc_msgSend
14 // CHECK: call void @llvm.objc.storeStrong(
15 // CHECK: call void @llvm.objc.storeStrong(
17 struct S1 { Class isa; };
19 @property (nonatomic, strong) __attribute__((NSObject)) struct S1 *pointer;
24 // The getter should be a simple load.
25 // CHECK: define internal [[S1:%.*]]* @"\01-[Test1 pointer]"(
26 // CHECK: [[OFFSET:%.*]] = load i64, i64* @"OBJC_IVAR_$_Test1.pointer"
27 // CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST1:%.*]]* {{%.*}} to i8*
28 // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8, i8* [[T0]], i64 [[OFFSET]]
29 // CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to [[S1]]**
30 // CHECK-NEXT: [[T3:%.*]] = load [[S1]]*, [[S1]]** [[T2]], align 8
31 // CHECK-NEXT: ret [[S1]]* [[T3]]
33 // The setter should be using objc_setProperty.
34 // CHECK: define internal void @"\01-[Test1 setPointer:]"(
35 // CHECK: [[T0:%.*]] = bitcast [[TEST1]]* {{%.*}} to i8*
36 // CHECK-NEXT: [[OFFSET:%.*]] = load i64, i64* @"OBJC_IVAR_$_Test1.pointer"
37 // CHECK-NEXT: [[T1:%.*]] = load [[S1]]*, [[S1]]** {{%.*}}
38 // CHECK-NEXT: [[T2:%.*]] = bitcast [[S1]]* [[T1]] to i8*
39 // CHECK-NEXT: call void @objc_setProperty(i8* noundef [[T0]], i8* noundef {{%.*}}, i64 noundef [[OFFSET]], i8* noundef [[T2]], i1 noundef zeroext false, i1 noundef zeroext false)
40 // CHECK-NEXT: ret void
43 // rdar://problem/12039404
48 @property (copy) Class theClass;
51 static Class theGlobalClass;
53 @synthesize theClass = _theClass;
55 _theClass = theGlobalClass;
58 // CHECK: define internal void @"\01-[Test2 test]"(
59 // CHECK: [[T0:%.*]] = load i8*, i8** @theGlobalClass, align 8
60 // CHECK-NEXT: [[T1:%.*]] = load [[TEST2:%.*]]*, [[TEST2:%.*]]**
61 // CHECK-NEXT: [[OFFSET:%.*]] = load i64, i64* @"OBJC_IVAR_$_Test2._theClass"
62 // CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST2]]* [[T1]] to i8*
63 // CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i8, i8* [[T2]], i64 [[OFFSET]]
64 // CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to i8**
65 // CHECK-NEXT: call void @llvm.objc.storeStrong(i8** [[T4]], i8* [[T0]]) [[NUW:#[0-9]+]]
66 // CHECK-NEXT: ret void
68 // CHECK: define internal i8* @"\01-[Test2 theClass]"(
69 // CHECK: [[OFFSET:%.*]] = load i64, i64* @"OBJC_IVAR_$_Test2._theClass"
70 // CHECK-NEXT: [[T0:%.*]] = tail call i8* @objc_getProperty(i8* noundef {{.*}}, i8* noundef {{.*}}, i64 noundef [[OFFSET]], i1 noundef zeroext true)
71 // CHECK-NEXT: ret i8* [[T0]]
73 // CHECK: define internal void @"\01-[Test2 setTheClass:]"(
74 // CHECK: [[T0:%.*]] = bitcast [[TEST2]]* {{%.*}} to i8*
75 // CHECK-NEXT: [[OFFSET:%.*]] = load i64, i64* @"OBJC_IVAR_$_Test2._theClass"
76 // CHECK-NEXT: [[T1:%.*]] = load i8*, i8** {{%.*}}
77 // CHECK-NEXT: call void @objc_setProperty(i8* noundef [[T0]], i8* noundef {{%.*}}, i64 noundef [[OFFSET]], i8* noundef [[T1]], i1 noundef zeroext true, i1 noundef zeroext true)
78 // CHECK-NEXT: ret void
80 // CHECK: define internal void @"\01-[Test2 .cxx_destruct]"(
81 // CHECK: [[T0:%.*]] = load [[TEST2]]*, [[TEST2]]**
82 // CHECK-NEXT: [[OFFSET:%.*]] = load i64, i64* @"OBJC_IVAR_$_Test2._theClass"
83 // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST2]]* [[T0]] to i8*
84 // CHECK-NEXT: [[T2:%.*]] = getelementptr inbounds i8, i8* [[T1]], i64 [[OFFSET]]
85 // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to i8**
86 // CHECK-NEXT: call void @llvm.objc.storeStrong(i8** [[T3]], i8* null) [[NUW]]
87 // CHECK-NEXT: ret void
91 @property id copyMachine;
94 void test3(Test3 *t) {
98 // CHECK: define{{.*}} void @test3([[TEST3:%.*]]*
100 // CHECK: [[T:%.*]] = alloca [[TEST3]]*,
101 // CHECK-NEXT: [[X:%.*]] = alloca i8*,
103 // CHECK: [[T0:%.*]] = load [[TEST3]]*, [[TEST3]]** [[T]],
104 // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST3]]* [[T0]] to i8*
105 // CHECK-NEXT: [[SEL:%.*]] = load i8*, i8** @OBJC_SELECTOR_REFERENCES
106 // CHECK-NEXT: [[T2:%.*]] = call i8* bitcast ({{.*}} @objc_msgSend to {{.*}})(i8* noundef [[T1]], i8* noundef [[SEL]])
107 // CHECK-NEXT: store i8* [[T2]], i8** [[X]],
109 // CHECK-NEXT: [[T0:%.*]] = load [[TEST3]]*, [[TEST3]]** [[T]],
110 // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST3]]* [[T0]] to i8*
111 // CHECK-NEXT: [[SEL:%.*]] = load i8*, i8** @OBJC_SELECTOR_REFERENCES
112 // CHECK-NEXT: [[T2:%.*]] = call i8* bitcast ({{.*}} @objc_msgSend to {{.*}})(i8* noundef [[T1]], i8* noundef [[SEL]])
113 // CHECK-NEXT: [[T3:%.*]] = load i8*, i8** [[X]],
114 // CHECK-NEXT: store i8* [[T2]], i8** [[X]],
115 // CHECK-NEXT: call void @llvm.objc.release(i8* [[T3]])
117 // CHECK-NEXT: call void @llvm.objc.storeStrong(i8** [[X]], i8* null)
118 // CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST3]]** [[T]] to i8**
119 // CHECK-NEXT: call void @llvm.objc.storeStrong(i8** [[T0]], i8* null)
120 // CHECK-NEXT: ret void
122 @implementation Test3
124 extern id test3_helper(void);
125 return test3_helper();
127 // CHECK: define internal i8* @"\01-[Test3 copyMachine]"(
128 // CHECK: [[T0:%.*]] = call i8* @test3_helper()
129 // CHECK-NEXT: [[T1:%.*]] = notail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* [[T0]])
130 // CHECK-NEXT: ret i8* [[T1]]
131 - (void) setCopyMachine: (id) x {}
135 // When synthesizing a property that's declared in multiple protocols, ensure
136 // that the setter is emitted if any of these declarations is readwrite.
138 @property (copy, nonatomic, readonly) Test3 *someId;
140 @protocol ABC__Mutable <ABC>
141 @property (copy, nonatomic, readwrite) Test3 *someId;
144 @interface ABC_Class <ABC, ABC__Mutable>
147 @implementation ABC_Class
148 @synthesize someId = _someId;
149 // CHECK: define internal %{{.*}}* @"\01-[ABC_Class someId]"
150 // CHECK: define internal void @"\01-[ABC_Class setSomeId:]"(
154 // CHECK: attributes [[NUW]] = { nounwind }