xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/implicit-copy-constructor.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -o - %s -std=c++11 | FileCheck %s
2f4a2713aSLionel Sambuc 
3f4a2713aSLionel Sambuc struct A {
4f4a2713aSLionel Sambuc   A();
5f4a2713aSLionel Sambuc   A(const A&);
6f4a2713aSLionel Sambuc   A(A&);
7f4a2713aSLionel Sambuc   ~A();
8f4a2713aSLionel Sambuc };
9f4a2713aSLionel Sambuc 
10f4a2713aSLionel Sambuc struct B {
11f4a2713aSLionel Sambuc   B();
12f4a2713aSLionel Sambuc   B(B&);
13f4a2713aSLionel Sambuc };
14f4a2713aSLionel Sambuc 
15f4a2713aSLionel Sambuc struct C {
CC16f4a2713aSLionel Sambuc   C() {}
17f4a2713aSLionel Sambuc   C(C& other, A a = A());
18f4a2713aSLionel Sambuc   int i, j;
19f4a2713aSLionel Sambuc };
20f4a2713aSLionel Sambuc 
21f4a2713aSLionel Sambuc struct POD {
22f4a2713aSLionel Sambuc   int array[3][4];
23f4a2713aSLionel Sambuc };
24f4a2713aSLionel Sambuc 
25f4a2713aSLionel Sambuc struct D : A, B, virtual C {
26f4a2713aSLionel Sambuc   D();
27f4a2713aSLionel Sambuc   int scalar;
28f4a2713aSLionel Sambuc   int scalar_array[2][3];
29f4a2713aSLionel Sambuc   B class_member;
30f4a2713aSLionel Sambuc   C class_member_array[2][3];
31f4a2713aSLionel Sambuc   POD pod_array[2][3];
32f4a2713aSLionel Sambuc 
33f4a2713aSLionel Sambuc   union {
34f4a2713aSLionel Sambuc     int x;
35f4a2713aSLionel Sambuc     float f[3];
36f4a2713aSLionel Sambuc   };
37f4a2713aSLionel Sambuc };
38f4a2713aSLionel Sambuc 
f(D d)39f4a2713aSLionel Sambuc void f(D d) {
40f4a2713aSLionel Sambuc   D d2(d);
41f4a2713aSLionel Sambuc }
42f4a2713aSLionel Sambuc 
43*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define linkonce_odr void @_ZN1DC1ERS_(%struct.D* %this, %struct.D* dereferenceable({{[0-9]+}})) unnamed_addr
44f4a2713aSLionel Sambuc // CHECK: call void @_ZN1AC1Ev
45f4a2713aSLionel Sambuc // CHECK: call void @_ZN1CC2ERS_1A
46f4a2713aSLionel Sambuc // CHECK: call void @_ZN1AD1Ev
47f4a2713aSLionel Sambuc // CHECK: call void @_ZN1AC2ERS_
48f4a2713aSLionel Sambuc // CHECK: call void @_ZN1BC2ERS_
49f4a2713aSLionel Sambuc // CHECK: {{call void @llvm.memcpy.p0i8.p0i8.i64.*i64 28}}
50f4a2713aSLionel Sambuc // CHECK: call void @_ZN1BC1ERS_
51f4a2713aSLionel Sambuc // CHECK: br
52f4a2713aSLionel Sambuc // CHECK: {{icmp ult.*, 2}}
53f4a2713aSLionel Sambuc // CHECK: {{icmp ult.*, 3}}
54f4a2713aSLionel Sambuc // CHECK: call void @_ZN1AC1Ev
55f4a2713aSLionel Sambuc // CHECK: call void @_ZN1CC1ERS_1A
56f4a2713aSLionel Sambuc // CHECK: call void @_ZN1AD1Ev
57f4a2713aSLionel Sambuc // CHECK: {{call void @llvm.memcpy.p0i8.p0i8.i64.*i64 300}}
58f4a2713aSLionel Sambuc // CHECK: ret void
59f4a2713aSLionel Sambuc 
60f4a2713aSLionel Sambuc 
f0X061f4a2713aSLionel Sambuc template<class T> struct X0 { void f0(T * ) { } };
X1X162f4a2713aSLionel Sambuc template <class > struct X1 { X1( X1& , int = 0 ) { } };
63f4a2713aSLionel Sambuc struct X2 { X1<int> result; };
test_X2()64f4a2713aSLionel Sambuc void test_X2()
65f4a2713aSLionel Sambuc {
66f4a2713aSLionel Sambuc   typedef X2 impl;
67f4a2713aSLionel Sambuc   typedef X0<impl> pimpl;
68f4a2713aSLionel Sambuc   impl* i;
69f4a2713aSLionel Sambuc   pimpl pdata;
70f4a2713aSLionel Sambuc   pdata.f0( new impl(*i));
71f4a2713aSLionel Sambuc }
72f4a2713aSLionel Sambuc 
73f4a2713aSLionel Sambuc // rdar://problem/9598341
74f4a2713aSLionel Sambuc namespace test3 {
75f4a2713aSLionel Sambuc   struct A { A(const A&); A&operator=(const A&); };
76f4a2713aSLionel Sambuc   struct B { A a; unsigned : 0; };
test(const B & x)77f4a2713aSLionel Sambuc   void test(const B &x) {
78f4a2713aSLionel Sambuc     B y = x;
79f4a2713aSLionel Sambuc     y = x;
80f4a2713aSLionel Sambuc   }
81f4a2713aSLionel Sambuc }
82f4a2713aSLionel Sambuc 
83f4a2713aSLionel Sambuc namespace test4 {
84f4a2713aSLionel Sambuc   // When determining whether to implement an array copy as a memcpy, look at
85f4a2713aSLionel Sambuc   // whether the *selected* constructor is trivial.
86f4a2713aSLionel Sambuc   struct S {
87f4a2713aSLionel Sambuc     int arr[5][5];
88f4a2713aSLionel Sambuc     S(S &);
89f4a2713aSLionel Sambuc     S(const S &) = default;
90f4a2713aSLionel Sambuc   };
91f4a2713aSLionel Sambuc   // CHECK: @_ZN5test42f1
f1(S a)92f4a2713aSLionel Sambuc   void f1(S a) {
93f4a2713aSLionel Sambuc     // CHECK-NOT: memcpy
94f4a2713aSLionel Sambuc     // CHECK: call void @_ZN5test41SC1ERS0_
95f4a2713aSLionel Sambuc     // CHECK-NOT: memcpy
96f4a2713aSLionel Sambuc     S b(a);
97f4a2713aSLionel Sambuc     // CHECK: }
98f4a2713aSLionel Sambuc   }
99f4a2713aSLionel Sambuc   // CHECK: @_ZN5test42f2
f2(const S a)100f4a2713aSLionel Sambuc   void f2(const S a) {
101f4a2713aSLionel Sambuc     // CHECK-NOT: call void @_ZN5test41SC1ERS0_
102f4a2713aSLionel Sambuc     // CHECK: memcpy
103f4a2713aSLionel Sambuc     // CHECK-NOT: call void @_ZN5test41SC1ERS0_
104f4a2713aSLionel Sambuc     S b(a);
105f4a2713aSLionel Sambuc     // CHECK: }
106f4a2713aSLionel Sambuc   }
107f4a2713aSLionel Sambuc }
108