rvalue-references.cpp revision b3d5e2f181269656c1b2dbc09eab1f449d5074aa
1// RUN: %clang_cc1 -std=c++0x -triple x86_64-apple-darwin10 -emit-llvm -o - %s | FileCheck %s 2 3 4struct Spacer { int x; }; 5struct A { double array[2]; }; 6struct B : Spacer, A { }; 7 8B &getB(); 9 10// CHECK: define %struct.A* @_Z4getAv() 11// CHECK: call %struct.B* @_Z4getBv() 12// CHECK-NEXT: bitcast %struct.B* 13// CHECK-NEXT: getelementptr i8* 14// CHECK-NEXT: bitcast i8* {{.*}} to %struct.A* 15// CHECK-NEXT: ret %struct.A* 16A &&getA() { return static_cast<A&&>(getB()); } 17 18int &getIntLValue(); 19int &&getIntXValue(); 20int getIntPRValue(); 21 22// CHECK: define i32* @_Z2f0v() 23// CHECK: call i32* @_Z12getIntLValuev() 24// CHECK-NEXT: ret i32* 25int &&f0() { return static_cast<int&&>(getIntLValue()); } 26 27// CHECK: define i32* @_Z2f1v() 28// CHECK: call i32* @_Z12getIntXValuev() 29// CHECK-NEXT: ret i32* 30int &&f1() { return static_cast<int&&>(getIntXValue()); } 31 32// CHECK: define i32* @_Z2f2v 33// CHECK: call i32 @_Z13getIntPRValuev() 34// CHECK-NEXT: store i32 {{.*}}, i32* 35// CHECK-NEXT: ret i32* 36int &&f2() { return static_cast<int&&>(getIntPRValue()); } 37 38bool ok; 39 40class C 41{ 42 int* state_; 43 44 C(const C&) = delete; 45 C& operator=(const C&) = delete; 46public: 47 C(int state) : state_(new int(state)) { } 48 49 C(C&& a) { 50 state_ = a.state_; 51 a.state_ = 0; 52 } 53 54 ~C() { 55 delete state_; 56 state_ = 0; 57 } 58}; 59 60C test(); 61 62// CHECK: define void @_Z15elide_copy_initv 63void elide_copy_init() { 64 ok = false; 65 // FIXME: We're doing an extra move here, when we shouldn't be! 66 // CHECK: call void @_Z4testv(%class.C* sret %ref.tmp) 67 // CHECK: call void @_ZN1CC1EOS_(%class.C* %a, %class.C* %ref.tmp) 68 // CHECK: call void @_ZN1CD1Ev(%class.C* %ref.tmp) 69 C a = test(); 70 // CHECK: call void @_ZN1CD1Ev(%class.C* %a) 71 // CHECK: ret void 72} 73 74// CHECK: define void @_Z16test_move_returnv 75C test_move_return() { 76 // CHECK: call void @_ZN1CC1Ei 77 C a1(3); 78 // CHECK: call void @_ZN1CC1Ei 79 C a2(4); 80 if (ok) 81 // CHECK: call void @_ZN1CC1EOS_ 82 return a1; 83 // CHECK: call void @_ZN1CC1EOS_ 84 return a2; 85 // CHECK: call void @_ZN1CD1Ev 86 // CHECK: call void @_ZN1CD1Ev 87 //CHECK: ret void 88} 89