John McCall | d1e40d5 | 2011-10-02 01:16:38 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fobjc-arc -fobjc-runtime-has-weak -fblocks -triple x86_64-apple-darwin10.0.0 -emit-llvm -o - %s | FileCheck %s |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 2 | |
| 3 | typedef __strong id strong_id; |
| 4 | typedef __weak id weak_id; |
| 5 | |
| 6 | // CHECK: define void @_Z8test_newP11objc_object |
| 7 | void test_new(id invalue) { |
Fariborz Jahanian | 41a6a3e | 2013-02-21 00:40:10 +0000 | [diff] [blame] | 8 | // CHECK: [[INVALUEADDR:%.*]] = alloca i8* |
| 9 | // CHECK-NEXT: store i8* null, i8** [[INVALUEADDR]] |
| 10 | // CHECK-NEXT: call void @objc_storeStrong(i8** [[INVALUEADDR]], i8* [[INVALUE:%.*]]) |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 11 | |
| 12 | // CHECK: call noalias i8* @_Znwm |
| 13 | // CHECK-NEXT: {{bitcast i8\*.*to i8\*\*}} |
| 14 | // CHECK-NEXT: store i8* null, i8** |
| 15 | new strong_id; |
| 16 | // CHECK: call noalias i8* @_Znwm |
| 17 | // CHECK-NEXT: {{bitcast i8\*.*to i8\*\*}} |
| 18 | // CHECK-NEXT: store i8* null, i8** |
| 19 | new weak_id; |
| 20 | |
| 21 | // CHECK: call noalias i8* @_Znwm |
| 22 | // CHECK-NEXT: {{bitcast i8\*.*to i8\*\*}} |
| 23 | // CHECK-NEXT: store i8* null, i8** |
| 24 | new __strong id; |
| 25 | // CHECK: call noalias i8* @_Znwm |
| 26 | // CHECK-NEXT: {{bitcast i8\*.*to i8\*\*}} |
| 27 | // CHECK-NEXT: store i8* null, i8** |
| 28 | new __weak id; |
| 29 | |
| 30 | // CHECK: call noalias i8* @_Znwm |
| 31 | // CHECK: call i8* @objc_retain |
| 32 | // CHECK: store i8* |
| 33 | new __strong id(invalue); |
| 34 | |
| 35 | // CHECK: call noalias i8* @_Znwm |
| 36 | // CHECK: call i8* @objc_initWeak |
| 37 | new __weak id(invalue); |
| 38 | |
John McCall | 015f33b | 2012-10-17 02:28:37 +0000 | [diff] [blame] | 39 | // CHECK: call void @objc_storeStrong |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 40 | // CHECK: ret void |
| 41 | } |
| 42 | |
| 43 | // CHECK: define void @_Z14test_array_new |
| 44 | void test_array_new() { |
| 45 | // CHECK: call noalias i8* @_Znam |
| 46 | // CHECK: store i64 17, i64* |
| 47 | // CHECK: call void @llvm.memset.p0i8.i64 |
| 48 | new strong_id[17]; |
| 49 | |
| 50 | // CHECK: call noalias i8* @_Znam |
| 51 | // CHECK: store i64 17, i64* |
| 52 | // CHECK: call void @llvm.memset.p0i8.i64 |
| 53 | new weak_id[17]; |
| 54 | // CHECK: ret void |
| 55 | } |
| 56 | |
| 57 | // CHECK: define void @_Z11test_deletePU8__strongP11objc_objectPU6__weakS0_ |
| 58 | void test_delete(__strong id *sptr, __weak id *wptr) { |
| 59 | // CHECK: br i1 |
| 60 | // CHECK: load i8** |
| 61 | // CHECK-NEXT: call void @objc_release |
| 62 | // CHECK: call void @_ZdlPv |
| 63 | delete sptr; |
| 64 | |
| 65 | // CHECK: call void @objc_destroyWeak |
| 66 | // CHECK: call void @_ZdlPv |
| 67 | delete wptr; |
| 68 | |
| 69 | // CHECK: ret void |
| 70 | } |
| 71 | |
| 72 | // CHECK: define void @_Z17test_array_deletePU8__strongP11objc_objectPU6__weakS0_ |
| 73 | void test_array_delete(__strong id *sptr, __weak id *wptr) { |
John McCall | 7cfd76c | 2011-07-13 01:41:37 +0000 | [diff] [blame] | 74 | // CHECK: icmp eq i8** [[BEGIN:%.*]], null |
| 75 | // CHECK: [[LEN:%.*]] = load i64* {{%.*}} |
John McCall | 7cfd76c | 2011-07-13 01:41:37 +0000 | [diff] [blame] | 76 | // CHECK: [[END:%.*]] = getelementptr inbounds i8** [[BEGIN]], i64 [[LEN]] |
John McCall | fbf780a | 2011-07-13 08:09:46 +0000 | [diff] [blame] | 77 | // CHECK-NEXT: icmp eq i8** [[BEGIN]], [[END]] |
John McCall | 7cfd76c | 2011-07-13 01:41:37 +0000 | [diff] [blame] | 78 | // CHECK: [[PAST:%.*]] = phi i8** [ [[END]], {{%.*}} ], [ [[CUR:%.*]], |
| 79 | // CHECK-NEXT: [[CUR]] = getelementptr inbounds i8** [[PAST]], i64 -1 |
John McCall | 015f33b | 2012-10-17 02:28:37 +0000 | [diff] [blame] | 80 | // CHECK-NEXT: call void @objc_storeStrong(i8** [[CUR]], i8* null) |
John McCall | 7cfd76c | 2011-07-13 01:41:37 +0000 | [diff] [blame] | 81 | // CHECK-NEXT: icmp eq i8** [[CUR]], [[BEGIN]] |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 82 | // CHECK: call void @_ZdaPv |
| 83 | delete [] sptr; |
| 84 | |
John McCall | 7cfd76c | 2011-07-13 01:41:37 +0000 | [diff] [blame] | 85 | // CHECK: icmp eq i8** [[BEGIN:%.*]], null |
| 86 | // CHECK: [[LEN:%.*]] = load i64* {{%.*}} |
John McCall | 7cfd76c | 2011-07-13 01:41:37 +0000 | [diff] [blame] | 87 | // CHECK: [[END:%.*]] = getelementptr inbounds i8** [[BEGIN]], i64 [[LEN]] |
John McCall | fbf780a | 2011-07-13 08:09:46 +0000 | [diff] [blame] | 88 | // CHECK-NEXT: icmp eq i8** [[BEGIN]], [[END]] |
John McCall | 7cfd76c | 2011-07-13 01:41:37 +0000 | [diff] [blame] | 89 | // CHECK: [[PAST:%.*]] = phi i8** [ [[END]], {{%.*}} ], [ [[CUR:%.*]], |
| 90 | // CHECK-NEXT: [[CUR]] = getelementptr inbounds i8** [[PAST]], i64 -1 |
| 91 | // CHECK-NEXT: call void @objc_destroyWeak(i8** [[CUR]]) |
| 92 | // CHECK-NEXT: icmp eq i8** [[CUR]], [[BEGIN]] |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 93 | // CHECK: call void @_ZdaPv |
| 94 | delete [] wptr; |
| 95 | } |