xref: /llvm-project/clang/test/CXX/special/class.copy/implicit-move-def.cpp (revision 30e304e2a646ccd5f34d5697cad0be9dcccfaa2d)
1d9d3b21cSMandeep Singh Grang // FIXME: %clang_cc1 -emit-llvm -triple %itanium_abi_triple -o - -std=c++11 %s | FileCheck %s
2c9bd88e6SHans Wennborg // RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple -o - -std=c++11 %s | FileCheck -check-prefix=CHECK-ASSIGN %s
3c9bd88e6SHans Wennborg // RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple -o - -std=c++11 %s | FileCheck -check-prefix=CHECK-CTOR %s
422653bacSSebastian Redl 
522653bacSSebastian Redl // construct
622653bacSSebastian Redl 
722653bacSSebastian Redl struct E {
822653bacSSebastian Redl   E();
922653bacSSebastian Redl   E(E&&);
1022653bacSSebastian Redl };
1122653bacSSebastian Redl 
1222653bacSSebastian Redl struct F {
1322653bacSSebastian Redl   F();
1422653bacSSebastian Redl   F(F&&);
1522653bacSSebastian Redl };
1622653bacSSebastian Redl 
1722653bacSSebastian Redl struct G {
1822653bacSSebastian Redl   E e;
1922653bacSSebastian Redl };
2022653bacSSebastian Redl 
2122653bacSSebastian Redl struct H : G {
2222653bacSSebastian Redl   F l;
2322653bacSSebastian Redl   E m;
2422653bacSSebastian Redl   F ar[2];
2522653bacSSebastian Redl };
2622653bacSSebastian Redl 
f()2722653bacSSebastian Redl void f() {
2822653bacSSebastian Redl   H s;
2922653bacSSebastian Redl   // CHECK: call void @_ZN1HC1EOS_
3022653bacSSebastian Redl   H t(static_cast<H&&>(s));
3122653bacSSebastian Redl }
3222653bacSSebastian Redl 
3322653bacSSebastian Redl 
3422653bacSSebastian Redl // assign
3522653bacSSebastian Redl 
3622653bacSSebastian Redl struct A {
3722653bacSSebastian Redl   A &operator =(A&&);
3822653bacSSebastian Redl };
3922653bacSSebastian Redl 
4022653bacSSebastian Redl struct B {
4122653bacSSebastian Redl   B &operator =(B&&);
4222653bacSSebastian Redl };
4322653bacSSebastian Redl 
4422653bacSSebastian Redl struct C {
4522653bacSSebastian Redl   A a;
4622653bacSSebastian Redl };
4722653bacSSebastian Redl 
4822653bacSSebastian Redl struct D : C {
4922653bacSSebastian Redl   A a;
5022653bacSSebastian Redl   B b;
5122653bacSSebastian Redl   A ar[2];
5222653bacSSebastian Redl };
5322653bacSSebastian Redl 
g()5422653bacSSebastian Redl void g() {
5522653bacSSebastian Redl   D d;
5622653bacSSebastian Redl   // CHECK: call {{.*}} @_ZN1DaSEOS_
5722653bacSSebastian Redl   d = D();
5822653bacSSebastian Redl }
5922653bacSSebastian Redl 
60528499bbSDouglas Gregor // PR10822
61528499bbSDouglas Gregor struct I {
62528499bbSDouglas Gregor   unsigned var[1];
63528499bbSDouglas Gregor };
64528499bbSDouglas Gregor 
65146b8e9aSDouglas Gregor // CHECK: define void @_Z1hv() nounwind {
h()66528499bbSDouglas Gregor void h() {
67528499bbSDouglas Gregor   I i;
68146b8e9aSDouglas Gregor   // CHECK: call void @llvm.memcpy.
69528499bbSDouglas Gregor   i = I();
70146b8e9aSDouglas Gregor   // CHECK-NEXT: ret void
71146b8e9aSDouglas Gregor }
72146b8e9aSDouglas Gregor 
73146b8e9aSDouglas Gregor // PR10860
74146b8e9aSDouglas Gregor struct Empty { };
75146b8e9aSDouglas Gregor struct VirtualWithEmptyBase : Empty {
76146b8e9aSDouglas Gregor   virtual void f();
77146b8e9aSDouglas Gregor };
78146b8e9aSDouglas Gregor 
79146b8e9aSDouglas Gregor // CHECK: define void @_Z25move_VirtualWithEmptyBaseR20VirtualWithEmptyBaseS0_
move_VirtualWithEmptyBase(VirtualWithEmptyBase & x,VirtualWithEmptyBase & y)80146b8e9aSDouglas Gregor void move_VirtualWithEmptyBase(VirtualWithEmptyBase &x, VirtualWithEmptyBase &y) {
81146b8e9aSDouglas Gregor   // CHECK: call {{.*}} @_ZN20VirtualWithEmptyBaseaSEOS_
82146b8e9aSDouglas Gregor   x = static_cast<VirtualWithEmptyBase&&>(y);
83146b8e9aSDouglas Gregor   // CHECK-NEXT: ret void
84528499bbSDouglas Gregor }
8522653bacSSebastian Redl 
8622653bacSSebastian Redl // move assignment ops
8722653bacSSebastian Redl 
88528499bbSDouglas Gregor // CHECK-ASSIGN: define linkonce_odr {{.*}} @_ZN1DaSEOS_
89528499bbSDouglas Gregor // CHECK-ASSIGN: call {{.*}} @_ZN1CaSEOS_
90528499bbSDouglas Gregor // CHECK-ASSIGN: call {{.*}} @_ZN1AaSEOS_
91528499bbSDouglas Gregor // CHECK-ASSIGN: call {{.*}} @_ZN1BaSEOS_
9222653bacSSebastian Redl // array loop
93528499bbSDouglas Gregor // CHECK-ASSIGN: br i1
94528499bbSDouglas Gregor // CHECK-ASSIGN: call {{.*}} @_ZN1AaSEOS_
9522653bacSSebastian Redl 
96146b8e9aSDouglas Gregor // VirtualWithEmptyBase move assignment operatpr
97146b8e9aSDouglas Gregor // CHECK-ASSIGN: define linkonce_odr {{.*}} @_ZN20VirtualWithEmptyBaseaSEOS_
98146b8e9aSDouglas Gregor // CHECK-ASSIGN: store
99146b8e9aSDouglas Gregor // CHECK-ASSIGN-NEXT: store
1003ba20c15SEli Friedman // CHECK-ASSIGN-NOT: call
1013ba20c15SEli Friedman // CHECK-ASSIGN: ret
10222653bacSSebastian Redl 
103528499bbSDouglas Gregor // CHECK-ASSIGN: define linkonce_odr {{.*}} @_ZN1CaSEOS_
104528499bbSDouglas Gregor // CHECK-ASSIGN: call {{.*}} @_ZN1AaSEOS_
10522653bacSSebastian Redl 
10622653bacSSebastian Redl // move ctors
10722653bacSSebastian Redl 
1083ba20c15SEli Friedman // CHECK-CTOR: define linkonce_odr {{.*}} @_ZN1HC2EOS_
1093ba20c15SEli Friedman // CHECK-CTOR: call {{.*}} @_ZN1GC2EOS_
1103ba20c15SEli Friedman // CHECK-CTOR: call {{.*}} @_ZN1FC1EOS_
1113ba20c15SEli Friedman // CHECK-CTOR: call {{.*}} @_ZN1EC1EOS_
11222653bacSSebastian Redl // array loop
1133ba20c15SEli Friedman // CHECK-CTOR: call {{.*}} @_ZN1FC1EOS_
114*30e304e2SRichard Smith // CHECK-CTOR: br i1
11522653bacSSebastian Redl 
1163ba20c15SEli Friedman // CHECK-CTOR: define linkonce_odr {{.*}} @_ZN1GC2EOS_
1173ba20c15SEli Friedman // CHECK-CTOR: call {{.*}} @_ZN1EC1EOS_
118