1f4a2713aSLionel Sambuc// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fblocks -fobjc-arc -O2 -std=c++11 -disable-llvm-optzns -o - %s | FileCheck %s 2f4a2713aSLionel Sambuc 3f4a2713aSLionel Sambuc// define void @_Z11simple_moveRU8__strongP11objc_objectS2_ 4f4a2713aSLionel Sambucvoid simple_move(__strong id &x, __strong id &y) { 5f4a2713aSLionel Sambuc // CHECK: = load i8** 6f4a2713aSLionel Sambuc // CHECK: store i8* null 7f4a2713aSLionel Sambuc // CHECK: = load i8** 8f4a2713aSLionel Sambuc // CHECK: store i8* 9f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release 10f4a2713aSLionel Sambuc x = static_cast<__strong id&&>(y); 11f4a2713aSLionel Sambuc // CHECK-NEXT: ret void 12f4a2713aSLionel Sambuc} 13f4a2713aSLionel Sambuc 14f4a2713aSLionel Sambuctemplate<typename T> 15f4a2713aSLionel Sambucstruct remove_reference { 16f4a2713aSLionel Sambuc typedef T type; 17f4a2713aSLionel Sambuc}; 18f4a2713aSLionel Sambuc 19f4a2713aSLionel Sambuctemplate<typename T> 20f4a2713aSLionel Sambucstruct remove_reference<T&> { 21f4a2713aSLionel Sambuc typedef T type; 22f4a2713aSLionel Sambuc}; 23f4a2713aSLionel Sambuc 24f4a2713aSLionel Sambuctemplate<typename T> 25f4a2713aSLionel Sambucstruct remove_reference<T&&> { 26f4a2713aSLionel Sambuc typedef T type; 27f4a2713aSLionel Sambuc}; 28f4a2713aSLionel Sambuc 29f4a2713aSLionel Sambuctemplate<typename T> 30f4a2713aSLionel Sambuctypename remove_reference<T>::type&& move(T &&x) { 31f4a2713aSLionel Sambuc return static_cast<typename remove_reference<T>::type&&>(x); 32f4a2713aSLionel Sambuc} 33f4a2713aSLionel Sambuc 34f4a2713aSLionel Sambuc// CHECK-LABEL: define void @_Z12library_moveRU8__strongP11objc_objectS2_ 35f4a2713aSLionel Sambucvoid library_move(__strong id &x, __strong id &y) { 36*0a6a1f1dSLionel Sambuc // CHECK: call dereferenceable({{[0-9]+}}) i8** @_Z4moveIRU8__strongP11objc_objectEON16remove_referenceIT_E4typeEOS5_ 37f4a2713aSLionel Sambuc // CHECK: load i8** 38f4a2713aSLionel Sambuc // CHECK: store i8* null, i8** 39f4a2713aSLionel Sambuc // CHECK: load i8*** 40f4a2713aSLionel Sambuc // CHECK-NEXT: load i8** 41f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* 42f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release 43f4a2713aSLionel Sambuc // CHECK-NEXT: ret void 44f4a2713aSLionel Sambuc x = move(y); 45f4a2713aSLionel Sambuc} 46f4a2713aSLionel Sambuc 47f4a2713aSLionel Sambuc// CHECK-LABEL: define void @_Z12library_moveRU8__strongP11objc_object 48f4a2713aSLionel Sambucvoid library_move(__strong id &y) { 49*0a6a1f1dSLionel Sambuc // CHECK: [[Y:%[a-zA-Z0-9]+]] = call dereferenceable({{[0-9]+}}) i8** @_Z4moveIRU8__strongP11objc_objectEON16remove_referenceIT_E4typeEOS5_ 50f4a2713aSLionel Sambuc // Load the object 51f4a2713aSLionel Sambuc // CHECK-NEXT: [[OBJ:%[a-zA-Z0-9]+]] = load i8** [[Y]] 52f4a2713aSLionel Sambuc // Null out y 53f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* null, i8** [[Y]] 54f4a2713aSLionel Sambuc // Initialize x with the object 55f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* [[OBJ]], i8** [[X:%[a-zA-Z0-9]+]] 56f4a2713aSLionel Sambuc id x = move(y); 57f4a2713aSLionel Sambuc 58f4a2713aSLionel Sambuc // CHECK-NEXT: store i32 17 59f4a2713aSLionel Sambuc int i = 17; 60f4a2713aSLionel Sambuc // CHECK-NEXT: [[OBJ:%[a-zA-Z0-9]+]] = load i8** [[X]] 61f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[OBJ]]) 62f4a2713aSLionel Sambuc // CHECK-NEXT: ret void 63f4a2713aSLionel Sambuc} 64f4a2713aSLionel Sambuc 65f4a2713aSLionel Sambuc// CHECK-LABEL: define void @_Z10const_moveRKU8__strongP11objc_object( 66f4a2713aSLionel Sambucvoid const_move(const __strong id &x) { 67f4a2713aSLionel Sambuc // CHECK: [[Y:%.*]] = alloca i8*, 68*0a6a1f1dSLionel Sambuc // CHECK: [[X:%.*]] = call dereferenceable({{[0-9]+}}) i8** @_Z4moveIRKU8__strongP11objc_objectEON16remove_referenceIT_E4typeEOS5_( 69f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = load i8** [[X]] 70f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retain(i8* [[T0]]) 71f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* [[T1]], i8** [[Y]] 72f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = load i8** [[Y]] 73f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T0]]) 74f4a2713aSLionel Sambuc id y = move(x); 75f4a2713aSLionel Sambuc} 76