Daniel Dunbar | 4fcfde4 | 2009-11-08 01:45:36 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -triple x86_64-apple-darwin -S %s -o %t-64.s |
| 2 | // RUN: FileCheck -check-prefix LP64 --input-file=%t-64.s %s |
| 3 | // RUN: clang-cc -triple i386-apple-darwin -S %s -o %t-32.s |
| 4 | // RUN: FileCheck -check-prefix LP32 --input-file=%t-32.s %s |
Fariborz Jahanian | 942f4f3 | 2009-08-08 23:32:22 +0000 | [diff] [blame] | 5 | |
| 6 | extern "C" int printf(...); |
| 7 | |
| 8 | int init = 100; |
| 9 | |
| 10 | struct M { |
| 11 | int iM; |
| 12 | M() : iM(init++) {} |
| 13 | }; |
| 14 | |
| 15 | struct N { |
| 16 | int iN; |
| 17 | N() : iN(200) {} |
| 18 | N(N const & arg){this->iN = arg.iN; } |
| 19 | }; |
| 20 | |
| 21 | struct P { |
| 22 | int iP; |
| 23 | P() : iP(init++) {} |
| 24 | }; |
| 25 | |
| 26 | |
| 27 | struct X : M, N, P { // ... |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 28 | X() : f1(1.0), d1(2.0), i1(3), name("HELLO"), bf1(0xff), bf2(0xabcd), |
| 29 | au_i1(1234), au1_4("MASKED") {} |
| 30 | P p0; |
| 31 | void pr() { |
| 32 | printf("iM = %d iN = %d, m1.iM = %d\n", iM, iN, m1.iM); |
| 33 | printf("im = %d p0.iP = %d, p1.iP = %d\n", iP, p0.iP, p1.iP); |
| 34 | printf("f1 = %f d1 = %f i1 = %d name(%s) \n", f1, d1, i1, name); |
| 35 | printf("bf1 = %x bf2 = %x\n", bf1, bf2); |
| 36 | printf("au_i2 = %d\n", au_i2); |
| 37 | printf("au1_1 = %s\n", au1_1); |
| 38 | } |
| 39 | M m1; |
| 40 | P p1; |
| 41 | float f1; |
| 42 | double d1; |
| 43 | int i1; |
| 44 | const char *name; |
| 45 | unsigned bf1 : 8; |
| 46 | unsigned bf2 : 16; |
Eli Friedman | 6d10ac9 | 2009-11-16 21:47:41 +0000 | [diff] [blame] | 47 | int arr[2]; |
| 48 | _Complex float complex; |
Fariborz Jahanian | e649412 | 2009-08-11 18:49:54 +0000 | [diff] [blame] | 49 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 50 | union { |
| 51 | int au_i1; |
| 52 | int au_i2; |
| 53 | }; |
| 54 | union { |
| 55 | const char * au1_1; |
| 56 | float au1_2; |
| 57 | int au1_3; |
| 58 | const char * au1_4; |
| 59 | }; |
Fariborz Jahanian | 942f4f3 | 2009-08-08 23:32:22 +0000 | [diff] [blame] | 60 | }; |
| 61 | |
Fariborz Jahanian | eb0b6d5 | 2009-08-21 18:30:26 +0000 | [diff] [blame] | 62 | static int ix = 1; |
| 63 | // class with user-defined copy constructor. |
| 64 | struct S { |
| 65 | S() : iS(ix++) { } |
| 66 | S(const S& arg) { *this = arg; } |
| 67 | int iS; |
| 68 | }; |
| 69 | |
| 70 | // class with trivial copy constructor. |
| 71 | struct I { |
| 72 | I() : iI(ix++) { } |
| 73 | int iI; |
| 74 | }; |
| 75 | |
| 76 | struct XM { |
| 77 | XM() { } |
| 78 | double dXM; |
| 79 | S ARR_S[3][4][2]; |
| 80 | void pr() { |
| 81 | for (unsigned i = 0; i < 3; i++) |
| 82 | for (unsigned j = 0; j < 4; j++) |
| 83 | for (unsigned k = 0; k < 2; k++) |
| 84 | printf("ARR_S[%d][%d][%d] = %d\n", i,j,k, ARR_S[i][j][k].iS); |
| 85 | for (unsigned i = 0; i < 3; i++) |
| 86 | for (unsigned k = 0; k < 2; k++) |
| 87 | printf("ARR_I[%d][%d] = %d\n", i,k, ARR_I[i][k].iI); |
| 88 | } |
| 89 | I ARR_I[3][2]; |
| 90 | }; |
| 91 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 92 | int main() { |
| 93 | X a; |
| 94 | X b(a); |
| 95 | b.pr(); |
| 96 | X x; |
| 97 | X c(x); |
| 98 | c.pr(); |
Fariborz Jahanian | eb0b6d5 | 2009-08-21 18:30:26 +0000 | [diff] [blame] | 99 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 100 | XM m0; |
| 101 | XM m1 = m0; |
| 102 | m1.pr(); |
Fariborz Jahanian | 942f4f3 | 2009-08-08 23:32:22 +0000 | [diff] [blame] | 103 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 104 | |
Anders Carlsson | d99edc4 | 2009-09-26 03:55:37 +0000 | [diff] [blame] | 105 | // CHECK-LP64: .globl __ZN1XC1ERKS_ |
| 106 | // CHECK-LP64: .weak_definition __ZN1XC1ERKS_ |
| 107 | // CHECK-LP64: __ZN1XC1ERKS_: |
Fariborz Jahanian | 942f4f3 | 2009-08-08 23:32:22 +0000 | [diff] [blame] | 108 | |
Anders Carlsson | d99edc4 | 2009-09-26 03:55:37 +0000 | [diff] [blame] | 109 | // CHECK-LP32: .globl __ZN1XC1ERKS_ |
| 110 | // CHECK-LP32: .weak_definition __ZN1XC1ERKS_ |
| 111 | // CHECK-LP32: __ZN1XC1ERKS_: |