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