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