1 // RUN: %clang_cc1 -fobjc-nonfragile-abi -fobjc-arc -fobjc-runtime-has-weak -fblocks -triple x86_64-apple-darwin10.0.0 -emit-llvm -o - %s | FileCheck %s 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) { 8 // CHECK: alloca i8* 9 // CHECK-NEXT: call i8* @objc_retain 10 11 // CHECK: call noalias i8* @_Znwm 12 // CHECK-NEXT: {{bitcast i8\*.*to i8\*\*}} 13 // CHECK-NEXT: store i8* null, i8** 14 new strong_id; 15 // CHECK: call noalias i8* @_Znwm 16 // CHECK-NEXT: {{bitcast i8\*.*to i8\*\*}} 17 // CHECK-NEXT: store i8* null, i8** 18 new weak_id; 19 20 // CHECK: call noalias i8* @_Znwm 21 // CHECK-NEXT: {{bitcast i8\*.*to i8\*\*}} 22 // CHECK-NEXT: store i8* null, i8** 23 new __strong id; 24 // CHECK: call noalias i8* @_Znwm 25 // CHECK-NEXT: {{bitcast i8\*.*to i8\*\*}} 26 // CHECK-NEXT: store i8* null, i8** 27 new __weak id; 28 29 // CHECK: call noalias i8* @_Znwm 30 // CHECK: call i8* @objc_retain 31 // CHECK: store i8* 32 new __strong id(invalue); 33 34 // CHECK: call noalias i8* @_Znwm 35 // CHECK: call i8* @objc_initWeak 36 new __weak id(invalue); 37 38 // CHECK: call void @objc_release 39 // CHECK: ret void 40 } 41 42 // CHECK: define void @_Z14test_array_new 43 void test_array_new() { 44 // CHECK: call noalias i8* @_Znam 45 // CHECK: store i64 17, i64* 46 // CHECK: call void @llvm.memset.p0i8.i64 47 new strong_id[17]; 48 49 // CHECK: call noalias i8* @_Znam 50 // CHECK: store i64 17, i64* 51 // CHECK: call void @llvm.memset.p0i8.i64 52 new weak_id[17]; 53 // CHECK: ret void 54 } 55 56 // CHECK: define void @_Z11test_deletePU8__strongP11objc_objectPU6__weakS0_ 57 void test_delete(__strong id *sptr, __weak id *wptr) { 58 // CHECK: br i1 59 // CHECK: load i8** 60 // CHECK-NEXT: call void @objc_release 61 // CHECK: call void @_ZdlPv 62 delete sptr; 63 64 // CHECK: call void @objc_destroyWeak 65 // CHECK: call void @_ZdlPv 66 delete wptr; 67 68 // CHECK: ret void 69 } 70 71 // CHECK: define void @_Z17test_array_deletePU8__strongP11objc_objectPU6__weakS0_ 72 void test_array_delete(__strong id *sptr, __weak id *wptr) { 73 // CHECK: icmp eq i8** [[BEGIN:%.*]], null 74 // CHECK: [[LEN:%.*]] = load i64* {{%.*}} 75 // CHECK: [[END:%.*]] = getelementptr inbounds i8** [[BEGIN]], i64 [[LEN]] 76 // CHECK-NEXT: icmp eq i8** [[BEGIN]], [[END]] 77 // CHECK: [[PAST:%.*]] = phi i8** [ [[END]], {{%.*}} ], [ [[CUR:%.*]], 78 // CHECK-NEXT: [[CUR]] = getelementptr inbounds i8** [[PAST]], i64 -1 79 // CHECK-NEXT: [[T0:%.*]] = load i8** [[CUR]] 80 // CHECK-NEXT: call void @objc_release(i8* [[T0]]) 81 // CHECK-NEXT: icmp eq i8** [[CUR]], [[BEGIN]] 82 // CHECK: call void @_ZdaPv 83 delete [] sptr; 84 85 // CHECK: icmp eq i8** [[BEGIN:%.*]], null 86 // CHECK: [[LEN:%.*]] = load i64* {{%.*}} 87 // CHECK: [[END:%.*]] = getelementptr inbounds i8** [[BEGIN]], i64 [[LEN]] 88 // CHECK-NEXT: icmp eq i8** [[BEGIN]], [[END]] 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]] 93 // CHECK: call void @_ZdaPv 94 delete [] wptr; 95 } 96