implicit-move-def.cpp revision d9f5b3363bc0edc314f0136cd66b22e545344fa5
1// RUN: %clang_cc1 -emit-llvm -o - -std=c++11 %s | FileCheck -check-prefix=CHECK-ASSIGN %s
2// RUN: %clang_cc1 -emit-llvm -o - -std=c++11 %s | FileCheck -check-prefix=CHECK-ASSIGN %s
3// RUN: %clang_cc1 -emit-llvm -o - -std=c++11 %s | FileCheck -check-prefix=CHECK-CTOR %s
4
5// construct
6
7struct E {
8  E();
9  E(E&&);
10};
11
12struct F {
13  F();
14  F(F&&);
15};
16
17struct G {
18  E e;
19};
20
21struct H : G {
22  F l;
23  E m;
24  F ar[2];
25};
26
27void f() {
28  H s;
29  // CHECK: call void @_ZN1HC1EOS_
30  H t(static_cast<H&&>(s));
31}
32
33
34// assign
35
36struct A {
37  A &operator =(A&&);
38};
39
40struct B {
41  B &operator =(B&&);
42};
43
44struct C {
45  A a;
46};
47
48struct D : C {
49  A a;
50  B b;
51  A ar[2];
52};
53
54void g() {
55  D d;
56  // CHECK: call {{.*}} @_ZN1DaSEOS_
57  d = D();
58}
59
60// PR10822
61struct I {
62  unsigned var[1];
63};
64
65// CHECK: define void @_Z1hv() nounwind {
66void h() {
67  I i;
68  // CHECK: call void @llvm.memcpy.
69  i = I();
70  // CHECK-NEXT: ret void
71}
72
73// PR10860
74struct Empty { };
75struct VirtualWithEmptyBase : Empty {
76  virtual void f();
77};
78
79// CHECK: define void @_Z25move_VirtualWithEmptyBaseR20VirtualWithEmptyBaseS0_
80void move_VirtualWithEmptyBase(VirtualWithEmptyBase &x, VirtualWithEmptyBase &y) {
81  // CHECK: call {{.*}} @_ZN20VirtualWithEmptyBaseaSEOS_
82  x = static_cast<VirtualWithEmptyBase&&>(y);
83  // CHECK-NEXT: ret void
84}
85
86// move assignment ops
87
88// CHECK-ASSIGN: define linkonce_odr {{.*}} @_ZN1DaSEOS_
89// CHECK-ASSIGN: call {{.*}} @_ZN1CaSEOS_
90// CHECK-ASSIGN: call {{.*}} @_ZN1AaSEOS_
91// CHECK-ASSIGN: call {{.*}} @_ZN1BaSEOS_
92// array loop
93// CHECK-ASSIGN: br i1
94// CHECK-ASSIGN: call {{.*}} @_ZN1AaSEOS_
95
96// VirtualWithEmptyBase move assignment operatpr
97// CHECK-ASSIGN: define linkonce_odr {{.*}} @_ZN20VirtualWithEmptyBaseaSEOS_
98// CHECK-ASSIGN: store
99// CHECK-ASSIGN-NEXT: store
100// CHECK-ASSIGN-NOT: call
101// CHECK-ASSIGN: ret
102
103// CHECK-ASSIGN: define linkonce_odr {{.*}} @_ZN1CaSEOS_
104// CHECK-ASSIGN: call {{.*}} @_ZN1AaSEOS_
105
106// move ctors
107
108// CHECK-CTOR: define linkonce_odr {{.*}} @_ZN1HC2EOS_
109// CHECK-CTOR: call {{.*}} @_ZN1GC2EOS_
110// CHECK-CTOR: call {{.*}} @_ZN1FC1EOS_
111// CHECK-CTOR: call {{.*}} @_ZN1EC1EOS_
112// array loop
113// CHECK-CTOR: br i1
114// CHECK-CTOR: call {{.*}} @_ZN1FC1EOS_
115
116// CHECK-CTOR: define linkonce_odr {{.*}} @_ZN1GC2EOS_
117// CHECK-CTOR: call {{.*}} @_ZN1EC1EOS_
118