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