2016-12-23 08:23:01 +08:00
|
|
|
// 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
|
2011-06-16 07:02:42 +08:00
|
|
|
|
2011-06-23 00:12:01 +08:00
|
|
|
@interface A
|
|
|
|
@end
|
|
|
|
|
2011-06-16 07:02:42 +08:00
|
|
|
id getObject();
|
|
|
|
void callee();
|
|
|
|
|
|
|
|
// Lifetime extension for binding a reference to an rvalue
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} void @_Z5test0v()
|
2011-06-16 07:02:42 +08:00
|
|
|
void test0() {
|
|
|
|
// CHECK: call i8* @_Z9getObjectv
|
2018-12-19 04:33:00 +08:00
|
|
|
// CHECK-NEXT: call i8* @llvm.objc.retainAutoreleasedReturnValue
|
2011-06-16 07:02:42 +08:00
|
|
|
const __strong id &ref1 = getObject();
|
|
|
|
// CHECK: call void @_Z6calleev
|
|
|
|
callee();
|
|
|
|
// CHECK: call i8* @_Z9getObjectv
|
2018-12-19 04:33:00 +08:00
|
|
|
// CHECK-NEXT: call i8* @llvm.objc.retainAutoreleasedReturnValue
|
|
|
|
// CHECK-NEXT: call i8* @llvm.objc.autorelease
|
2011-06-16 07:02:42 +08:00
|
|
|
const __autoreleasing id &ref2 = getObject();
|
|
|
|
// CHECK: call void @_Z6calleev
|
|
|
|
callee();
|
2018-12-19 04:33:00 +08:00
|
|
|
// CHECK: call void @llvm.objc.release
|
2017-04-15 00:53:25 +08:00
|
|
|
// CHECK: ret
|
2011-06-16 07:02:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// No lifetime extension when we're binding a reference to an lvalue.
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} void @_Z5test1RU8__strongP11objc_objectRU6__weakS0_
|
2011-06-16 07:02:42 +08:00
|
|
|
void test1(__strong id &x, __weak id &y) {
|
|
|
|
// CHECK-NOT: release
|
|
|
|
const __strong id &ref1 = x;
|
|
|
|
const __autoreleasing id &ref2 = x;
|
|
|
|
const __weak id &ref3 = y;
|
|
|
|
// CHECK: ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef __strong id strong_id;
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
//CHECK: define{{.*}} void @_Z5test3v
|
2011-06-16 07:02:42 +08:00
|
|
|
void test3() {
|
2015-04-23 05:38:15 +08:00
|
|
|
// CHECK: [[REF:%.*]] = alloca i8**, align 8
|
2018-12-19 04:33:00 +08:00
|
|
|
// CHECK: call i8* @llvm.objc.initWeak
|
2011-06-16 07:02:42 +08:00
|
|
|
// CHECK-NEXT: store i8**
|
|
|
|
const __weak id &ref = strong_id();
|
|
|
|
// CHECK-NEXT: call void @_Z6calleev()
|
|
|
|
callee();
|
2018-12-19 04:33:00 +08:00
|
|
|
// CHECK-NEXT: call void @llvm.objc.destroyWeak
|
2015-04-23 05:38:15 +08:00
|
|
|
// CHECK-NEXT: [[PTR:%.*]] = bitcast i8*** [[REF]] to i8*
|
2017-04-11 04:18:45 +08:00
|
|
|
// CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 8, i8* [[PTR]])
|
2011-06-16 07:02:42 +08:00
|
|
|
// CHECK-NEXT: ret void
|
|
|
|
}
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} void @_Z5test4RU8__strongP11objc_object
|
2011-06-23 00:12:01 +08:00
|
|
|
void test4(__strong id &x) {
|
2018-12-19 04:33:00 +08:00
|
|
|
// CHECK: call i8* @llvm.objc.retain
|
2011-06-23 00:12:01 +08:00
|
|
|
__strong A* const &ar = x;
|
|
|
|
// CHECK: store i32 17, i32*
|
|
|
|
int i = 17;
|
2018-12-19 04:33:00 +08:00
|
|
|
// CHECK: call void @llvm.objc.release(
|
2011-06-23 00:12:01 +08:00
|
|
|
// CHECK: ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
void sink(__strong A* &&);
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} void @_Z5test5RU8__strongP11objc_object
|
2011-06-23 00:12:01 +08:00
|
|
|
void test5(__strong id &x) {
|
2011-08-27 05:08:13 +08:00
|
|
|
// CHECK: [[REFTMP:%.*]] = alloca {{%.*}}*, align 8
|
2015-04-23 05:38:15 +08:00
|
|
|
// CHECK: [[I:%.*]] = alloca i32, align 4
|
2018-12-19 04:33:00 +08:00
|
|
|
// CHECK: [[OBJ_ID:%.*]] = call i8* @llvm.objc.retain(
|
2011-08-27 05:08:13 +08:00
|
|
|
// CHECK-NEXT: [[OBJ_A:%.*]] = bitcast i8* [[OBJ_ID]] to [[A:%[a-zA-Z0-9]+]]*
|
2011-06-23 00:12:01 +08:00
|
|
|
// CHECK-NEXT: store [[A]]* [[OBJ_A]], [[A]]** [[REFTMP:%[a-zA-Z0-9]+]]
|
|
|
|
// CHECK-NEXT: call void @_Z4sinkOU8__strongP1A
|
|
|
|
sink(x);
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[OBJ_A:%[a-zA-Z0-9]+]] = load [[A]]*, [[A]]** [[REFTMP]]
|
2011-06-23 00:12:01 +08:00
|
|
|
// CHECK-NEXT: [[OBJ_ID:%[a-zA-Z0-9]+]] = bitcast [[A]]* [[OBJ_A]] to i8*
|
2018-12-19 04:33:00 +08:00
|
|
|
// CHECK-NEXT: call void @llvm.objc.release
|
2015-04-23 05:38:15 +08:00
|
|
|
// CHECK-NEXT: [[IPTR1:%.*]] = bitcast i32* [[I]] to i8*
|
2017-04-11 04:18:45 +08:00
|
|
|
// CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 4, i8* [[IPTR1]])
|
2011-06-23 00:12:01 +08:00
|
|
|
// CHECK-NEXT: store i32 17, i32
|
|
|
|
int i = 17;
|
2015-04-23 05:38:15 +08:00
|
|
|
// CHECK-NEXT: [[IPTR2:%.*]] = bitcast i32* [[I]] to i8*
|
2017-04-11 04:18:45 +08:00
|
|
|
// CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 4, i8* [[IPTR2]])
|
2011-06-23 00:12:01 +08:00
|
|
|
// CHECK-NEXT: ret void
|
|
|
|
}
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define internal void @__cxx_global_var_init(
|
2011-06-16 07:02:42 +08:00
|
|
|
// CHECK: call i8* @_Z9getObjectv
|
2018-12-19 04:33:00 +08:00
|
|
|
// CHECK-NEXT: call i8* @llvm.objc.retainAutoreleasedReturnValue
|
2011-06-16 07:02:42 +08:00
|
|
|
const __strong id &global_ref = getObject();
|
|
|
|
|
|
|
|
// Note: we intentionally don't release the object.
|
|
|
|
|