[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / clang / test / CodeGenCXX / rvalue-references.cpp
blob3a4a93c32122cd509666a3ccbf40b942277d5283
1 // RUN: %clang_cc1 -std=c++11 -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-LABEL: define{{.*}} nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_Z4getAv()
11 // CHECK: call noundef nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_Z4getBv()
12 // CHECK-NEXT: getelementptr inbounds i8, ptr
13 // CHECK-NEXT: ret ptr
14 A &&getA() { return static_cast<A&&>(getB()); }
16 int &getIntLValue();
17 int &&getIntXValue();
18 int getIntPRValue();
20 // CHECK-LABEL: define{{.*}} nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_Z2f0v()
21 // CHECK: call noundef nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_Z12getIntLValuev()
22 // CHECK-NEXT: ret ptr
23 int &&f0() { return static_cast<int&&>(getIntLValue()); }
25 // CHECK-LABEL: define{{.*}} nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_Z2f1v()
26 // CHECK: call noundef nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_Z12getIntXValuev()
27 // CHECK-NEXT: ret ptr
28 int &&f1() { return static_cast<int&&>(getIntXValue()); }
30 // CHECK-LABEL: define{{.*}} nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_Z2f2v
31 // CHECK: call noundef i32 @_Z13getIntPRValuev()
32 // CHECK-NEXT: store i32 {{.*}}, ptr
33 // CHECK-NEXT: ret ptr
34 int &&f2() { return static_cast<int&&>(getIntPRValue()); }
36 bool ok;
38 class C
40 int* state_;
42 C(const C&) = delete;
43 C& operator=(const C&) = delete;
44 public:
45 C(int state) : state_(new int(state)) { }
47 C(C&& a) {
48 state_ = a.state_;
49 a.state_ = 0;
52 ~C() {
53 delete state_;
54 state_ = 0;
58 C test();
60 // CHECK-LABEL: define{{.*}} void @_Z15elide_copy_initv
61 void elide_copy_init() {
62 ok = false;
63 // CHECK: call void @_Z4testv
64 C a = test();
65 // CHECK-NEXT: call void @_ZN1CD1Ev
66 // CHECK-NEXT: ret void
69 // CHECK-LABEL: define{{.*}} void @_Z16test_move_returnv
70 C test_move_return() {
71 // CHECK: call void @_ZN1CC1Ei
72 C a1(3);
73 // CHECK: call void @_ZN1CC1Ei
74 C a2(4);
75 if (ok)
76 // CHECK: call void @_ZN1CC1EOS_
77 return a1;
78 // CHECK: call void @_ZN1CC1EOS_
79 return a2;
80 // CHECK: call void @_ZN1CD1Ev
81 // CHECK: call void @_ZN1CD1Ev
82 //CHECK: ret void
85 // PR10800: don't crash
86 namespace test1 {
87 int &&move(int&);
89 struct A { A(int); };
90 struct B {
91 A a;
92 B(int i);
95 // CHECK-LABEL: define{{.*}} void @_ZN5test11BC2Ei(
96 // CHECK: [[T0:%.*]] = call noundef nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_ZN5test14moveERi(
97 // CHECK-NEXT: [[T1:%.*]] = load i32, ptr [[T0]]
98 // CHECK-NEXT: call void @_ZN5test11AC1Ei({{.*}}, i32 noundef [[T1]])
99 // CHECK-NEXT: ret void
100 B::B(int i) : a(move(i)) {}
103 // PR11009
104 struct MoveConvertible {
105 operator int&& () const;
107 void moveConstruct() {
108 (void)(int)MoveConvertible();