[Heikki Kultala] This patch contains the ABI changes for the TCE target.
[clang.git] / test / CodeGenCXX / rvalue-references.cpp
blobe15172355ebd19784822d731c370cac9015dbf51
1 // RUN: %clang_cc1 -std=c++0x -triple x86_64-apple-darwin10 -emit-llvm -o - %s | FileCheck %s
4 struct Spacer { int x; };
5 struct A { double array[2]; };
6 struct B : Spacer, A { };
8 B &getB();
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*
16 A &&getA() { return static_cast<A&&>(getB()); }
18 int &getIntLValue();
19 int &&getIntXValue();
20 int getIntPRValue();
22 // CHECK: define i32* @_Z2f0v()
23 // CHECK: call i32* @_Z12getIntLValuev()
24 // CHECK-NEXT: ret i32*
25 int &&f0() { return static_cast<int&&>(getIntLValue()); }
27 // CHECK: define i32* @_Z2f1v()
28 // CHECK: call i32* @_Z12getIntXValuev()
29 // CHECK-NEXT: ret i32*
30 int &&f1() { return static_cast<int&&>(getIntXValue()); }
32 // CHECK: define i32* @_Z2f2v
33 // CHECK: call i32 @_Z13getIntPRValuev()
34 // CHECK-NEXT: store i32 {{.*}}, i32*
35 // CHECK-NEXT: ret i32*
36 int &&f2() { return static_cast<int&&>(getIntPRValue()); }
38 bool ok;
40 class C
42 int* state_;
44 C(const C&) = delete;
45 C& operator=(const C&) = delete;
46 public:
47 C(int state) : state_(new int(state)) { }
49 C(C&& a) {
50 state_ = a.state_;
51 a.state_ = 0;
54 ~C() {
55 delete state_;
56 state_ = 0;
60 C test();
62 // CHECK: define void @_Z15elide_copy_initv
63 void elide_copy_init() {
64 ok = false;
65 // CHECK: call void @_Z4testv
66 C a = test();
67 // CHECK-NEXT: call void @_ZN1CD1Ev
68 // CHECK-NEXT: ret void
71 // CHECK: define void @_Z16test_move_returnv
72 C test_move_return() {
73 // CHECK: call void @_ZN1CC1Ei
74 C a1(3);
75 // CHECK: call void @_ZN1CC1Ei
76 C a2(4);
77 if (ok)
78 // CHECK: call void @_ZN1CC1EOS_
79 return a1;
80 // CHECK: call void @_ZN1CC1EOS_
81 return a2;
82 // CHECK: call void @_ZN1CD1Ev
83 // CHECK: call void @_ZN1CD1Ev
84 //CHECK: ret void