Mike Stump | c5708d9 | 2009-08-06 14:12:47 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -triple x86_64-apple-darwin -frtti=0 -std=c++0x -O3 -S %s -o %t-64.s && |
Mike Stump | 06758d0 | 2009-08-04 20:37:29 +0000 | [diff] [blame] | 2 | // RUN: FileCheck -check-prefix LP64 --input-file=%t-64.s %s && |
Mike Stump | c5708d9 | 2009-08-06 14:12:47 +0000 | [diff] [blame] | 3 | // RUN: clang-cc -triple i386-apple-darwin -frtti=0 -std=c++0x -O3 -S %s -o %t-32.s && |
Mike Stump | 06758d0 | 2009-08-04 20:37:29 +0000 | [diff] [blame] | 4 | // RUN: FileCheck -check-prefix LP32 -input-file=%t-32.s %s && |
| 5 | // RUN: true |
Mike Stump | 3dee6ef | 2009-07-30 00:22:38 +0000 | [diff] [blame] | 6 | |
Mike Stump | 104ffaa | 2009-08-04 21:58:42 +0000 | [diff] [blame] | 7 | struct B { |
| 8 | virtual void bar1(); |
| 9 | virtual void bar2(); |
Mike Stump | 2effeca | 2009-08-06 00:38:46 +0000 | [diff] [blame] | 10 | int b; |
Mike Stump | 104ffaa | 2009-08-04 21:58:42 +0000 | [diff] [blame] | 11 | }; |
Mike Stump | 6f37633 | 2009-08-05 22:37:18 +0000 | [diff] [blame] | 12 | void B::bar1() { } |
| 13 | void B::bar2() { } |
| 14 | |
| 15 | struct C { |
| 16 | virtual void bee1(); |
| 17 | virtual void bee2(); |
| 18 | }; |
| 19 | void C::bee1() { } |
| 20 | void C::bee2() { } |
Mike Stump | 104ffaa | 2009-08-04 21:58:42 +0000 | [diff] [blame] | 21 | |
Mike Stump | 2effeca | 2009-08-06 00:38:46 +0000 | [diff] [blame] | 22 | struct D { |
| 23 | virtual void boo(); |
| 24 | }; |
| 25 | void D::boo() { } |
Mike Stump | 104ffaa | 2009-08-04 21:58:42 +0000 | [diff] [blame] | 26 | |
Mike Stump | c5708d9 | 2009-08-06 14:12:47 +0000 | [diff] [blame] | 27 | struct D1 { |
| 28 | virtual void bar(); |
| 29 | void *d1; |
| 30 | }; |
| 31 | void D1::bar() { } |
| 32 | |
| 33 | class F : virtual public D1, virtual public D { |
| 34 | public: |
| 35 | virtual void foo(); |
| 36 | void *f; |
| 37 | }; |
| 38 | void F::foo() { } |
| 39 | |
| 40 | int j; |
| 41 | void test2() { |
| 42 | F f; |
| 43 | static int sz = (char *)(&f.f) - (char *)(&f); |
| 44 | j = sz; |
Mike Stump | 37148f4 | 2009-08-06 14:16:19 +0000 | [diff] [blame] | 45 | // FIXME: These should result in a frontend constant a la fold, no run time |
| 46 | // initializer |
Mike Stump | c5708d9 | 2009-08-06 14:12:47 +0000 | [diff] [blame] | 47 | // CHECK-LP32: movl $4, __ZZ5test2vE2sz |
| 48 | // CHECK-LP64: movl $8, __ZZ5test2vE2sz(%rip) |
| 49 | } |
Mike Stump | 8a12b56 | 2009-08-06 15:50:11 +0000 | [diff] [blame] | 50 | |
Mike Stump | c5708d9 | 2009-08-06 14:12:47 +0000 | [diff] [blame] | 51 | static_assert(sizeof(F) == sizeof(void*)*4, "invalid vbase size"); |
| 52 | |
Mike Stump | 2effeca | 2009-08-06 00:38:46 +0000 | [diff] [blame] | 53 | struct E { |
| 54 | int e; |
| 55 | }; |
| 56 | |
| 57 | static_assert (sizeof (C) == (sizeof(void *)), "vtable pointer layout"); |
| 58 | |
Mike Stump | eb19fa9 | 2009-08-06 13:41:24 +0000 | [diff] [blame] | 59 | class A : public E, public B, public C { |
Mike Stump | 3dee6ef | 2009-07-30 00:22:38 +0000 | [diff] [blame] | 60 | public: |
Mike Stump | 06758d0 | 2009-08-04 20:37:29 +0000 | [diff] [blame] | 61 | virtual void foo1(); |
| 62 | virtual void foo2(); |
| 63 | A() { } |
Mike Stump | 2effeca | 2009-08-06 00:38:46 +0000 | [diff] [blame] | 64 | int a; |
| 65 | } *ap; |
Mike Stump | 6f37633 | 2009-08-05 22:37:18 +0000 | [diff] [blame] | 66 | void A::foo1() { } |
| 67 | void A::foo2() { } |
Mike Stump | 3dee6ef | 2009-07-30 00:22:38 +0000 | [diff] [blame] | 68 | |
Mike Stump | 06758d0 | 2009-08-04 20:37:29 +0000 | [diff] [blame] | 69 | int main() { |
| 70 | A a; |
Mike Stump | 26899b0 | 2009-08-05 22:48:36 +0000 | [diff] [blame] | 71 | B b; |
Mike Stump | 2effeca | 2009-08-06 00:38:46 +0000 | [diff] [blame] | 72 | ap->e = 1; |
| 73 | ap->b = 2; |
Mike Stump | 06758d0 | 2009-08-04 20:37:29 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Mike Stump | 2effeca | 2009-08-06 00:38:46 +0000 | [diff] [blame] | 76 | // CHECK-LP32: main: |
| 77 | // CHECK-LP32: movl $1, 8(%eax) |
| 78 | // CHECK-LP32: movl $2, 4(%eax) |
| 79 | |
| 80 | // CHECK-LP64: main: |
| 81 | // CHECK-LP64: movl $1, 12(%rax) |
| 82 | // CHECK-LP64: movl $2, 8(%rax) |
| 83 | |
Mike Stump | 26899b0 | 2009-08-05 22:48:36 +0000 | [diff] [blame] | 84 | // CHECK-LP64: __ZTV1B: |
| 85 | // CHECK-LP64: .space 8 |
| 86 | // CHECK-LP64: .space 8 |
| 87 | // CHECK-LP64: .quad __ZN1B4bar1Ev |
| 88 | // CHECK-LP64: .quad __ZN1B4bar2Ev |
| 89 | |
| 90 | // CHECK-LP32: __ZTV1B: |
| 91 | // CHECK-LP32: .space 4 |
| 92 | // CHECK-LP32: .space 4 |
| 93 | // CHECK-LP32: .long __ZN1B4bar1Ev |
| 94 | // CHECK-LP32: .long __ZN1B4bar2Ev |
| 95 | |
Mike Stump | 06758d0 | 2009-08-04 20:37:29 +0000 | [diff] [blame] | 96 | // CHECK-LP64: __ZTV1A: |
| 97 | // CHECK-LP64: .space 8 |
| 98 | // CHECK-LP64: .space 8 |
Mike Stump | 104ffaa | 2009-08-04 21:58:42 +0000 | [diff] [blame] | 99 | // CHECK-LP64: .quad __ZN1B4bar1Ev |
| 100 | // CHECK-LP64: .quad __ZN1B4bar2Ev |
Mike Stump | 06758d0 | 2009-08-04 20:37:29 +0000 | [diff] [blame] | 101 | // CHECK-LP64: .quad __ZN1A4foo1Ev |
| 102 | // CHECK-LP64: .quad __ZN1A4foo2Ev |
Mike Stump | 2effeca | 2009-08-06 00:38:46 +0000 | [diff] [blame] | 103 | // CHECK-LP64: .quad 18446744073709551600 |
Mike Stump | 6f37633 | 2009-08-05 22:37:18 +0000 | [diff] [blame] | 104 | // CHECK-LP64: .space 8 |
| 105 | // CHECK-LP64: .quad __ZN1C4bee1Ev |
| 106 | // CHECK-LP64: .quad __ZN1C4bee2Ev |
Mike Stump | 06758d0 | 2009-08-04 20:37:29 +0000 | [diff] [blame] | 107 | |
| 108 | // CHECK-LP32: __ZTV1A: |
| 109 | // CHECK-LP32: .space 4 |
| 110 | // CHECK-LP32: .space 4 |
Mike Stump | 104ffaa | 2009-08-04 21:58:42 +0000 | [diff] [blame] | 111 | // CHECK-LP32: .long __ZN1B4bar1Ev |
| 112 | // CHECK-LP32: .long __ZN1B4bar2Ev |
Mike Stump | 06758d0 | 2009-08-04 20:37:29 +0000 | [diff] [blame] | 113 | // CHECK-LP32: .long __ZN1A4foo1Ev |
| 114 | // CHECK-LP32: .long __ZN1A4foo2Ev |
Mike Stump | 2effeca | 2009-08-06 00:38:46 +0000 | [diff] [blame] | 115 | // CHECK-LP32: .long 4294967284 |
Mike Stump | 6f37633 | 2009-08-05 22:37:18 +0000 | [diff] [blame] | 116 | // CHECK-LP32: .space 4 |
| 117 | // CHECK-LP32: .long __ZN1C4bee1Ev |
| 118 | // CHECK-LP32: .long __ZN1C4bee2Ev |
Mike Stump | 8a12b56 | 2009-08-06 15:50:11 +0000 | [diff] [blame] | 119 | |
| 120 | // CHECK-LP32: __ZTV1F: |
| 121 | // CHECK-LP32 .space 4 |
| 122 | // CHECK-LP32 .long 8 |
| 123 | // CHECK-LP32 .space 4 |
| 124 | // CHECK-LP32: .space 4 |
| 125 | // CHECK-LP32: .space 4 |
Mike Stump | 70101ce | 2009-08-06 18:05:22 +0000 | [diff] [blame^] | 126 | // CHECK-LP32: .long __ZN1D3booEv |
| 127 | // CHECK-LP32: .long __ZN1F3fooEv |
Mike Stump | 8a12b56 | 2009-08-06 15:50:11 +0000 | [diff] [blame] | 128 | // CHECK-LP32 .space 4 |
| 129 | // CHECK-LP32 .long -8 |
| 130 | // CHECK-LP32 .space 4 |
| 131 | // CHECK-LP32: .long __ZN2D13barEv |
| 132 | |
| 133 | // CHECK-LP64: __ZTV1F: |
| 134 | // CHECK-LP64 .space 8 |
| 135 | // CHECK-LP64 .quad 16 |
| 136 | // CHECK-LP64 .space 8 |
| 137 | // CHECK-LP64: .space 8 |
| 138 | // CHECK-LP64: .space 8 |
Mike Stump | 70101ce | 2009-08-06 18:05:22 +0000 | [diff] [blame^] | 139 | // CHECK-LP64: .quad __ZN1D3booEv |
| 140 | // CHECK-LP64: .quad __ZN1F3fooEv |
Mike Stump | 8a12b56 | 2009-08-06 15:50:11 +0000 | [diff] [blame] | 141 | // CHECK-LP64 .space 8 |
| 142 | // CHECK-LP64 .space -16 |
| 143 | // CHECK-LP64 .space 8 |
| 144 | // CHECK-LP64: .quad __ZN2D13barEv |