Anders Carlsson | d09020d | 2010-03-30 02:53:30 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - %s | FileCheck %s |
Fariborz Jahanian | 942f4f3 | 2009-08-08 23:32:22 +0000 | [diff] [blame] | 2 | |
| 3 | extern "C" int printf(...); |
| 4 | |
| 5 | int init = 100; |
| 6 | |
| 7 | struct M { |
| 8 | int iM; |
| 9 | M() : iM(init++) {} |
| 10 | }; |
| 11 | |
| 12 | struct N { |
| 13 | int iN; |
| 14 | N() : iN(200) {} |
| 15 | N(N const & arg){this->iN = arg.iN; } |
| 16 | }; |
| 17 | |
| 18 | struct P { |
| 19 | int iP; |
| 20 | P() : iP(init++) {} |
| 21 | }; |
| 22 | |
| 23 | |
Rafael Espindola | 0691a5c | 2011-01-25 19:10:24 +0000 | [diff] [blame] | 24 | // CHECK: define linkonce_odr void @_ZN1XC1ERKS_(%struct.X* %this, %struct.X*) unnamed_addr |
Fariborz Jahanian | 942f4f3 | 2009-08-08 23:32:22 +0000 | [diff] [blame] | 25 | struct X : M, N, P { // ... |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 26 | X() : f1(1.0), d1(2.0), i1(3), name("HELLO"), bf1(0xff), bf2(0xabcd), |
| 27 | au_i1(1234), au1_4("MASKED") {} |
| 28 | P p0; |
| 29 | void pr() { |
| 30 | printf("iM = %d iN = %d, m1.iM = %d\n", iM, iN, m1.iM); |
| 31 | printf("im = %d p0.iP = %d, p1.iP = %d\n", iP, p0.iP, p1.iP); |
| 32 | printf("f1 = %f d1 = %f i1 = %d name(%s) \n", f1, d1, i1, name); |
| 33 | printf("bf1 = %x bf2 = %x\n", bf1, bf2); |
| 34 | printf("au_i2 = %d\n", au_i2); |
| 35 | printf("au1_1 = %s\n", au1_1); |
| 36 | } |
| 37 | M m1; |
| 38 | P p1; |
| 39 | float f1; |
| 40 | double d1; |
| 41 | int i1; |
| 42 | const char *name; |
| 43 | unsigned bf1 : 8; |
| 44 | unsigned bf2 : 16; |
Eli Friedman | 6d10ac9 | 2009-11-16 21:47:41 +0000 | [diff] [blame] | 45 | int arr[2]; |
| 46 | _Complex float complex; |
Fariborz Jahanian | e649412 | 2009-08-11 18:49:54 +0000 | [diff] [blame] | 47 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 48 | union { |
| 49 | int au_i1; |
| 50 | int au_i2; |
| 51 | }; |
| 52 | union { |
| 53 | const char * au1_1; |
| 54 | float au1_2; |
| 55 | int au1_3; |
| 56 | const char * au1_4; |
| 57 | }; |
Fariborz Jahanian | 942f4f3 | 2009-08-08 23:32:22 +0000 | [diff] [blame] | 58 | }; |
| 59 | |
Fariborz Jahanian | eb0b6d5 | 2009-08-21 18:30:26 +0000 | [diff] [blame] | 60 | static int ix = 1; |
| 61 | // class with user-defined copy constructor. |
| 62 | struct S { |
| 63 | S() : iS(ix++) { } |
| 64 | S(const S& arg) { *this = arg; } |
| 65 | int iS; |
| 66 | }; |
| 67 | |
| 68 | // class with trivial copy constructor. |
| 69 | struct I { |
| 70 | I() : iI(ix++) { } |
| 71 | int iI; |
| 72 | }; |
| 73 | |
| 74 | struct XM { |
| 75 | XM() { } |
| 76 | double dXM; |
| 77 | S ARR_S[3][4][2]; |
| 78 | void pr() { |
| 79 | for (unsigned i = 0; i < 3; i++) |
| 80 | for (unsigned j = 0; j < 4; j++) |
| 81 | for (unsigned k = 0; k < 2; k++) |
| 82 | printf("ARR_S[%d][%d][%d] = %d\n", i,j,k, ARR_S[i][j][k].iS); |
| 83 | for (unsigned i = 0; i < 3; i++) |
| 84 | for (unsigned k = 0; k < 2; k++) |
| 85 | printf("ARR_I[%d][%d] = %d\n", i,k, ARR_I[i][k].iI); |
| 86 | } |
| 87 | I ARR_I[3][2]; |
| 88 | }; |
| 89 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 90 | int main() { |
| 91 | X a; |
| 92 | X b(a); |
| 93 | b.pr(); |
| 94 | X x; |
| 95 | X c(x); |
| 96 | c.pr(); |
Fariborz Jahanian | eb0b6d5 | 2009-08-21 18:30:26 +0000 | [diff] [blame] | 97 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 98 | XM m0; |
| 99 | XM m1 = m0; |
| 100 | m1.pr(); |
Fariborz Jahanian | 942f4f3 | 2009-08-08 23:32:22 +0000 | [diff] [blame] | 101 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 102 | |
Anders Carlsson | e9cbf15 | 2009-11-24 21:08:10 +0000 | [diff] [blame] | 103 | struct A { |
| 104 | }; |
| 105 | |
| 106 | struct B : A { |
| 107 | A &a; |
| 108 | }; |
| 109 | |
| 110 | void f(const B &b1) { |
| 111 | B b2(b1); |
| 112 | } |
Anders Carlsson | 46bbf8d | 2010-03-30 02:57:48 +0000 | [diff] [blame] | 113 | |
| 114 | // PR6628 |
| 115 | namespace PR6628 { |
| 116 | |
| 117 | struct T { |
| 118 | T(); |
| 119 | ~T(); |
| 120 | |
| 121 | double d; |
| 122 | }; |
| 123 | |
| 124 | struct A { |
| 125 | A(const A &other, const T &t = T(), const T& t2 = T()); |
| 126 | }; |
| 127 | |
| 128 | struct B : A { |
| 129 | A a1; |
| 130 | A a2; |
Anders Carlsson | 8887bdc | 2010-03-30 03:30:08 +0000 | [diff] [blame] | 131 | A a[10]; |
Anders Carlsson | 46bbf8d | 2010-03-30 02:57:48 +0000 | [diff] [blame] | 132 | }; |
| 133 | |
| 134 | // Force the copy constructor to be synthesized. |
| 135 | void f(B b1) { |
| 136 | B b2 = b1; |
| 137 | } |
| 138 | |
Rafael Espindola | 0691a5c | 2011-01-25 19:10:24 +0000 | [diff] [blame] | 139 | // CHECK: define linkonce_odr void @_ZN6PR66281BC2ERKS0_(%"struct.PR6628::B"* %this, %"struct.PR6628::B"*) unnamed_addr |
Anders Carlsson | 46bbf8d | 2010-03-30 02:57:48 +0000 | [diff] [blame] | 140 | // CHECK: call void @_ZN6PR66281TC1Ev |
| 141 | // CHECK: call void @_ZN6PR66281TC1Ev |
| 142 | // CHECK: call void @_ZN6PR66281AC2ERKS0_RKNS_1TES5_ |
| 143 | // CHECK: call void @_ZN6PR66281TD1Ev |
| 144 | // CHECK: call void @_ZN6PR66281TD1Ev |
| 145 | // CHECK: call void @_ZN6PR66281TC1Ev |
| 146 | // CHECK: call void @_ZN6PR66281TC1Ev |
| 147 | // CHECK: call void @_ZN6PR66281AC1ERKS0_RKNS_1TES5_ |
| 148 | // CHECK: call void @_ZN6PR66281TD1Ev |
| 149 | // CHECK: call void @_ZN6PR66281TD1Ev |
| 150 | // CHECK: call void @_ZN6PR66281TC1Ev |
| 151 | // CHECK: call void @_ZN6PR66281TC1Ev |
| 152 | // CHECK: call void @_ZN6PR66281AC1ERKS0_RKNS_1TES5_ |
| 153 | // CHECK: call void @_ZN6PR66281TD1Ev |
| 154 | // CHECK: call void @_ZN6PR66281TD1Ev |
| 155 | } |
| 156 | |