2016-12-23 08:23:01 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fblocks -fobjc-arc -O2 -std=c++11 -disable-llvm-passes -o - %s | FileCheck %s
|
2011-06-23 00:32:26 +08:00
|
|
|
|
|
|
|
// define void @_Z11simple_moveRU8__strongP11objc_objectS2_
|
|
|
|
void simple_move(__strong id &x, __strong id &y) {
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: = load i8*, i8**
|
2011-06-23 00:32:26 +08:00
|
|
|
// CHECK: store i8* null
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: = load i8*, i8**
|
2011-06-23 00:32:26 +08:00
|
|
|
// CHECK: store i8*
|
2018-12-19 04:33:00 +08:00
|
|
|
// CHECK-NEXT: call void @llvm.objc.release
|
2011-06-23 00:32:26 +08:00
|
|
|
x = static_cast<__strong id&&>(y);
|
|
|
|
// CHECK-NEXT: ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct remove_reference {
|
|
|
|
typedef T type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct remove_reference<T&> {
|
|
|
|
typedef T type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct remove_reference<T&&> {
|
|
|
|
typedef T type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
typename remove_reference<T>::type&& move(T &&x) {
|
|
|
|
return static_cast<typename remove_reference<T>::type&&>(x);
|
|
|
|
}
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z12library_moveRU8__strongP11objc_objectS2_
|
2011-06-23 00:32:26 +08:00
|
|
|
void library_move(__strong id &x, __strong id &y) {
|
2014-07-18 23:52:10 +08:00
|
|
|
// CHECK: call dereferenceable({{[0-9]+}}) i8** @_Z4moveIRU8__strongP11objc_objectEON16remove_referenceIT_E4typeEOS5_
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: load i8*, i8**
|
2011-06-23 00:32:26 +08:00
|
|
|
// CHECK: store i8* null, i8**
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: load i8**, i8***
|
|
|
|
// CHECK-NEXT: load i8*, i8**
|
2011-06-23 00:32:26 +08:00
|
|
|
// CHECK-NEXT: store i8*
|
2018-12-19 04:33:00 +08:00
|
|
|
// CHECK-NEXT: call void @llvm.objc.release
|
2011-06-23 00:32:26 +08:00
|
|
|
// CHECK-NEXT: ret void
|
|
|
|
x = move(y);
|
|
|
|
}
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z12library_moveRU8__strongP11objc_object
|
2011-06-23 00:32:26 +08:00
|
|
|
void library_move(__strong id &y) {
|
2015-04-23 05:38:15 +08:00
|
|
|
// CHECK: [[X:%.*]] = alloca i8*, align 8
|
|
|
|
// CHECK: [[I:%.*]] = alloca i32, align 4
|
|
|
|
// CHECK: [[XPTR1:%.*]] = bitcast i8** [[X]] to i8*
|
2017-04-11 04:18:45 +08:00
|
|
|
// CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 8, i8* [[XPTR1]])
|
2014-07-18 23:52:10 +08:00
|
|
|
// CHECK: [[Y:%[a-zA-Z0-9]+]] = call dereferenceable({{[0-9]+}}) i8** @_Z4moveIRU8__strongP11objc_objectEON16remove_referenceIT_E4typeEOS5_
|
2011-06-23 00:32:26 +08:00
|
|
|
// Load the object
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[OBJ:%[a-zA-Z0-9]+]] = load i8*, i8** [[Y]]
|
2011-06-23 00:32:26 +08:00
|
|
|
// Null out y
|
|
|
|
// CHECK-NEXT: store i8* null, i8** [[Y]]
|
|
|
|
// Initialize x with the object
|
|
|
|
// CHECK-NEXT: store i8* [[OBJ]], i8** [[X:%[a-zA-Z0-9]+]]
|
|
|
|
id x = move(y);
|
|
|
|
|
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:32:26 +08:00
|
|
|
// CHECK-NEXT: store i32 17
|
|
|
|
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]])
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[OBJ:%[a-zA-Z0-9]+]] = load i8*, i8** [[X]]
|
2018-12-19 04:33:00 +08:00
|
|
|
// CHECK-NEXT: call void @llvm.objc.release(i8* [[OBJ]])
|
2015-04-23 05:38:15 +08:00
|
|
|
// CHECK-NEXT: [[XPTR2:%.*]] = bitcast i8** [[X]] to i8*
|
2017-04-11 04:18:45 +08:00
|
|
|
// CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 8, i8* [[XPTR2]])
|
2011-06-23 00:32:26 +08:00
|
|
|
// CHECK-NEXT: ret void
|
|
|
|
}
|
2011-06-25 10:26:44 +08:00
|
|
|
|
2016-03-02 06:18:03 +08:00
|
|
|
// CHECK-LABEL: define void @_Z10const_moveRU8__strongKP11objc_object(
|
2011-06-25 10:26:44 +08:00
|
|
|
void const_move(const __strong id &x) {
|
|
|
|
// CHECK: [[Y:%.*]] = alloca i8*,
|
2016-03-02 06:18:03 +08:00
|
|
|
// CHECK: [[X:%.*]] = call dereferenceable({{[0-9]+}}) i8** @_Z4moveIRU8__strongKP11objc_objectEON16remove_referenceIT_E4typeEOS5_(
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[T0:%.*]] = load i8*, i8** [[X]]
|
2018-12-19 04:33:00 +08:00
|
|
|
// CHECK-NEXT: [[T1:%.*]] = call i8* @llvm.objc.retain(i8* [[T0]])
|
2011-06-25 10:26:44 +08:00
|
|
|
// CHECK-NEXT: store i8* [[T1]], i8** [[Y]]
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[T0:%.*]] = load i8*, i8** [[Y]]
|
2018-12-19 04:33:00 +08:00
|
|
|
// CHECK-NEXT: call void @llvm.objc.release(i8* [[T0]])
|
2011-06-25 10:26:44 +08:00
|
|
|
id y = move(x);
|
|
|
|
}
|