annotate clang/test/CodeGenObjCXX/arc-references.mm @ 222:81f6424ef0e3 llvm-original

LLVM original branch
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 18 Jul 2021 22:10:01 +0900
parents 79ff65ed7e25
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-runtime-has-weak -fblocks -fobjc-arc -O2 -disable-llvm-passes -o - %s | FileCheck %s
anatofuz
parents:
diff changeset
2
anatofuz
parents:
diff changeset
3 @interface A
anatofuz
parents:
diff changeset
4 @end
anatofuz
parents:
diff changeset
5
anatofuz
parents:
diff changeset
6 id getObject();
anatofuz
parents:
diff changeset
7 void callee();
anatofuz
parents:
diff changeset
8
anatofuz
parents:
diff changeset
9 // Lifetime extension for binding a reference to an rvalue
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
10 // CHECK-LABEL: define{{.*}} void @_Z5test0v()
150
anatofuz
parents:
diff changeset
11 void test0() {
anatofuz
parents:
diff changeset
12 // CHECK: call i8* @_Z9getObjectv
anatofuz
parents:
diff changeset
13 // CHECK-NEXT: call i8* @llvm.objc.retainAutoreleasedReturnValue
anatofuz
parents:
diff changeset
14 const __strong id &ref1 = getObject();
anatofuz
parents:
diff changeset
15 // CHECK: call void @_Z6calleev
anatofuz
parents:
diff changeset
16 callee();
anatofuz
parents:
diff changeset
17 // CHECK: call i8* @_Z9getObjectv
anatofuz
parents:
diff changeset
18 // CHECK-NEXT: call i8* @llvm.objc.retainAutoreleasedReturnValue
anatofuz
parents:
diff changeset
19 // CHECK-NEXT: call i8* @llvm.objc.autorelease
anatofuz
parents:
diff changeset
20 const __autoreleasing id &ref2 = getObject();
anatofuz
parents:
diff changeset
21 // CHECK: call void @_Z6calleev
anatofuz
parents:
diff changeset
22 callee();
anatofuz
parents:
diff changeset
23 // CHECK: call void @llvm.objc.release
anatofuz
parents:
diff changeset
24 // CHECK: ret
anatofuz
parents:
diff changeset
25 }
anatofuz
parents:
diff changeset
26
anatofuz
parents:
diff changeset
27 // No lifetime extension when we're binding a reference to an lvalue.
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
28 // CHECK-LABEL: define{{.*}} void @_Z5test1RU8__strongP11objc_objectRU6__weakS0_
150
anatofuz
parents:
diff changeset
29 void test1(__strong id &x, __weak id &y) {
anatofuz
parents:
diff changeset
30 // CHECK-NOT: release
anatofuz
parents:
diff changeset
31 const __strong id &ref1 = x;
anatofuz
parents:
diff changeset
32 const __autoreleasing id &ref2 = x;
anatofuz
parents:
diff changeset
33 const __weak id &ref3 = y;
anatofuz
parents:
diff changeset
34 // CHECK: ret void
anatofuz
parents:
diff changeset
35 }
anatofuz
parents:
diff changeset
36
anatofuz
parents:
diff changeset
37 typedef __strong id strong_id;
anatofuz
parents:
diff changeset
38
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
39 //CHECK: define{{.*}} void @_Z5test3v
150
anatofuz
parents:
diff changeset
40 void test3() {
anatofuz
parents:
diff changeset
41 // CHECK: [[REF:%.*]] = alloca i8**, align 8
anatofuz
parents:
diff changeset
42 // CHECK: call i8* @llvm.objc.initWeak
anatofuz
parents:
diff changeset
43 // CHECK-NEXT: store i8**
anatofuz
parents:
diff changeset
44 const __weak id &ref = strong_id();
anatofuz
parents:
diff changeset
45 // CHECK-NEXT: call void @_Z6calleev()
anatofuz
parents:
diff changeset
46 callee();
anatofuz
parents:
diff changeset
47 // CHECK-NEXT: call void @llvm.objc.destroyWeak
anatofuz
parents:
diff changeset
48 // CHECK-NEXT: [[PTR:%.*]] = bitcast i8*** [[REF]] to i8*
anatofuz
parents:
diff changeset
49 // CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 8, i8* [[PTR]])
anatofuz
parents:
diff changeset
50 // CHECK-NEXT: ret void
anatofuz
parents:
diff changeset
51 }
anatofuz
parents:
diff changeset
52
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
53 // CHECK-LABEL: define{{.*}} void @_Z5test4RU8__strongP11objc_object
150
anatofuz
parents:
diff changeset
54 void test4(__strong id &x) {
anatofuz
parents:
diff changeset
55 // CHECK: call i8* @llvm.objc.retain
anatofuz
parents:
diff changeset
56 __strong A* const &ar = x;
anatofuz
parents:
diff changeset
57 // CHECK: store i32 17, i32*
anatofuz
parents:
diff changeset
58 int i = 17;
anatofuz
parents:
diff changeset
59 // CHECK: call void @llvm.objc.release(
anatofuz
parents:
diff changeset
60 // CHECK: ret void
anatofuz
parents:
diff changeset
61 }
anatofuz
parents:
diff changeset
62
anatofuz
parents:
diff changeset
63 void sink(__strong A* &&);
anatofuz
parents:
diff changeset
64
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
65 // CHECK-LABEL: define{{.*}} void @_Z5test5RU8__strongP11objc_object
150
anatofuz
parents:
diff changeset
66 void test5(__strong id &x) {
anatofuz
parents:
diff changeset
67 // CHECK: [[REFTMP:%.*]] = alloca {{%.*}}*, align 8
anatofuz
parents:
diff changeset
68 // CHECK: [[I:%.*]] = alloca i32, align 4
anatofuz
parents:
diff changeset
69 // CHECK: [[OBJ_ID:%.*]] = call i8* @llvm.objc.retain(
anatofuz
parents:
diff changeset
70 // CHECK-NEXT: [[OBJ_A:%.*]] = bitcast i8* [[OBJ_ID]] to [[A:%[a-zA-Z0-9]+]]*
anatofuz
parents:
diff changeset
71 // CHECK-NEXT: store [[A]]* [[OBJ_A]], [[A]]** [[REFTMP:%[a-zA-Z0-9]+]]
anatofuz
parents:
diff changeset
72 // CHECK-NEXT: call void @_Z4sinkOU8__strongP1A
anatofuz
parents:
diff changeset
73 sink(x);
anatofuz
parents:
diff changeset
74 // CHECK-NEXT: [[OBJ_A:%[a-zA-Z0-9]+]] = load [[A]]*, [[A]]** [[REFTMP]]
anatofuz
parents:
diff changeset
75 // CHECK-NEXT: [[OBJ_ID:%[a-zA-Z0-9]+]] = bitcast [[A]]* [[OBJ_A]] to i8*
anatofuz
parents:
diff changeset
76 // CHECK-NEXT: call void @llvm.objc.release
anatofuz
parents:
diff changeset
77 // CHECK-NEXT: [[IPTR1:%.*]] = bitcast i32* [[I]] to i8*
anatofuz
parents:
diff changeset
78 // CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 4, i8* [[IPTR1]])
anatofuz
parents:
diff changeset
79 // CHECK-NEXT: store i32 17, i32
anatofuz
parents:
diff changeset
80 int i = 17;
anatofuz
parents:
diff changeset
81 // CHECK-NEXT: [[IPTR2:%.*]] = bitcast i32* [[I]] to i8*
anatofuz
parents:
diff changeset
82 // CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 4, i8* [[IPTR2]])
anatofuz
parents:
diff changeset
83 // CHECK-NEXT: ret void
anatofuz
parents:
diff changeset
84 }
anatofuz
parents:
diff changeset
85
anatofuz
parents:
diff changeset
86 // CHECK-LABEL: define internal void @__cxx_global_var_init(
anatofuz
parents:
diff changeset
87 // CHECK: call i8* @_Z9getObjectv
anatofuz
parents:
diff changeset
88 // CHECK-NEXT: call i8* @llvm.objc.retainAutoreleasedReturnValue
anatofuz
parents:
diff changeset
89 const __strong id &global_ref = getObject();
anatofuz
parents:
diff changeset
90
anatofuz
parents:
diff changeset
91 // Note: we intentionally don't release the object.
anatofuz
parents:
diff changeset
92