Mike Stump | e1be2b1 | 2009-08-06 21:49:36 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -triple x86_64-apple-darwin -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 | e1be2b1 | 2009-08-06 21:49:36 +0000 | [diff] [blame] | 3 | // RUN: clang-cc -triple i386-apple-darwin -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(); |
Mike Stump | 02cf1e2 | 2009-08-06 23:48:32 +0000 | [diff] [blame] | 29 | virtual void bar2(); |
| 30 | virtual void bar3(); |
| 31 | virtual void bar4(); |
| 32 | virtual void bar5(); |
Mike Stump | c5708d9 | 2009-08-06 14:12:47 +0000 | [diff] [blame] | 33 | void *d1; |
| 34 | }; |
| 35 | void D1::bar() { } |
| 36 | |
| 37 | class F : virtual public D1, virtual public D { |
| 38 | public: |
| 39 | virtual void foo(); |
| 40 | void *f; |
| 41 | }; |
| 42 | void F::foo() { } |
| 43 | |
| 44 | int j; |
| 45 | void test2() { |
| 46 | F f; |
| 47 | static int sz = (char *)(&f.f) - (char *)(&f); |
| 48 | j = sz; |
Mike Stump | 37148f4 | 2009-08-06 14:16:19 +0000 | [diff] [blame] | 49 | // FIXME: These should result in a frontend constant a la fold, no run time |
| 50 | // initializer |
Mike Stump | c5708d9 | 2009-08-06 14:12:47 +0000 | [diff] [blame] | 51 | // CHECK-LP32: movl $4, __ZZ5test2vE2sz |
| 52 | // CHECK-LP64: movl $8, __ZZ5test2vE2sz(%rip) |
| 53 | } |
Mike Stump | 8a12b56 | 2009-08-06 15:50:11 +0000 | [diff] [blame] | 54 | |
Mike Stump | c5708d9 | 2009-08-06 14:12:47 +0000 | [diff] [blame] | 55 | static_assert(sizeof(F) == sizeof(void*)*4, "invalid vbase size"); |
| 56 | |
Mike Stump | 2effeca | 2009-08-06 00:38:46 +0000 | [diff] [blame] | 57 | struct E { |
| 58 | int e; |
| 59 | }; |
| 60 | |
| 61 | static_assert (sizeof (C) == (sizeof(void *)), "vtable pointer layout"); |
| 62 | |
Mike Stump | eb19fa9 | 2009-08-06 13:41:24 +0000 | [diff] [blame] | 63 | class A : public E, public B, public C { |
Mike Stump | 3dee6ef | 2009-07-30 00:22:38 +0000 | [diff] [blame] | 64 | public: |
Mike Stump | 06758d0 | 2009-08-04 20:37:29 +0000 | [diff] [blame] | 65 | virtual void foo1(); |
| 66 | virtual void foo2(); |
| 67 | A() { } |
Mike Stump | 2effeca | 2009-08-06 00:38:46 +0000 | [diff] [blame] | 68 | int a; |
| 69 | } *ap; |
Mike Stump | 6f37633 | 2009-08-05 22:37:18 +0000 | [diff] [blame] | 70 | void A::foo1() { } |
| 71 | void A::foo2() { } |
Mike Stump | 3dee6ef | 2009-07-30 00:22:38 +0000 | [diff] [blame] | 72 | |
Mike Stump | 06758d0 | 2009-08-04 20:37:29 +0000 | [diff] [blame] | 73 | int main() { |
| 74 | A a; |
Mike Stump | 26899b0 | 2009-08-05 22:48:36 +0000 | [diff] [blame] | 75 | B b; |
Mike Stump | 2effeca | 2009-08-06 00:38:46 +0000 | [diff] [blame] | 76 | ap->e = 1; |
| 77 | ap->b = 2; |
Mike Stump | 06758d0 | 2009-08-04 20:37:29 +0000 | [diff] [blame] | 78 | } |
| 79 | |
Mike Stump | 2effeca | 2009-08-06 00:38:46 +0000 | [diff] [blame] | 80 | // CHECK-LP32: main: |
| 81 | // CHECK-LP32: movl $1, 8(%eax) |
| 82 | // CHECK-LP32: movl $2, 4(%eax) |
| 83 | |
| 84 | // CHECK-LP64: main: |
| 85 | // CHECK-LP64: movl $1, 12(%rax) |
| 86 | // CHECK-LP64: movl $2, 8(%rax) |
| 87 | |
Mike Stump | 26899b0 | 2009-08-05 22:48:36 +0000 | [diff] [blame] | 88 | // CHECK-LP64: __ZTV1B: |
| 89 | // CHECK-LP64: .space 8 |
Mike Stump | e1be2b1 | 2009-08-06 21:49:36 +0000 | [diff] [blame] | 90 | // CHECK-LP64: .quad __ZTI1B |
Mike Stump | 26899b0 | 2009-08-05 22:48:36 +0000 | [diff] [blame] | 91 | // CHECK-LP64: .quad __ZN1B4bar1Ev |
| 92 | // CHECK-LP64: .quad __ZN1B4bar2Ev |
| 93 | |
| 94 | // CHECK-LP32: __ZTV1B: |
| 95 | // CHECK-LP32: .space 4 |
Mike Stump | e1be2b1 | 2009-08-06 21:49:36 +0000 | [diff] [blame] | 96 | // CHECK-LP32: .long __ZTI1B |
Mike Stump | 26899b0 | 2009-08-05 22:48:36 +0000 | [diff] [blame] | 97 | // CHECK-LP32: .long __ZN1B4bar1Ev |
| 98 | // CHECK-LP32: .long __ZN1B4bar2Ev |
| 99 | |
Mike Stump | 06758d0 | 2009-08-04 20:37:29 +0000 | [diff] [blame] | 100 | // CHECK-LP64: __ZTV1A: |
| 101 | // CHECK-LP64: .space 8 |
Mike Stump | e1be2b1 | 2009-08-06 21:49:36 +0000 | [diff] [blame] | 102 | // CHECK-LP64: .quad __ZTI1A |
Mike Stump | 104ffaa | 2009-08-04 21:58:42 +0000 | [diff] [blame] | 103 | // CHECK-LP64: .quad __ZN1B4bar1Ev |
| 104 | // CHECK-LP64: .quad __ZN1B4bar2Ev |
Mike Stump | 06758d0 | 2009-08-04 20:37:29 +0000 | [diff] [blame] | 105 | // CHECK-LP64: .quad __ZN1A4foo1Ev |
| 106 | // CHECK-LP64: .quad __ZN1A4foo2Ev |
Mike Stump | 2effeca | 2009-08-06 00:38:46 +0000 | [diff] [blame] | 107 | // CHECK-LP64: .quad 18446744073709551600 |
Mike Stump | e1be2b1 | 2009-08-06 21:49:36 +0000 | [diff] [blame] | 108 | // CHECK-LP64: .quad __ZTI1A |
Mike Stump | 6f37633 | 2009-08-05 22:37:18 +0000 | [diff] [blame] | 109 | // CHECK-LP64: .quad __ZN1C4bee1Ev |
| 110 | // CHECK-LP64: .quad __ZN1C4bee2Ev |
Mike Stump | 06758d0 | 2009-08-04 20:37:29 +0000 | [diff] [blame] | 111 | |
| 112 | // CHECK-LP32: __ZTV1A: |
| 113 | // CHECK-LP32: .space 4 |
Mike Stump | e1be2b1 | 2009-08-06 21:49:36 +0000 | [diff] [blame] | 114 | // CHECK-LP32: .long __ZTI1A |
Mike Stump | 104ffaa | 2009-08-04 21:58:42 +0000 | [diff] [blame] | 115 | // CHECK-LP32: .long __ZN1B4bar1Ev |
| 116 | // CHECK-LP32: .long __ZN1B4bar2Ev |
Mike Stump | 06758d0 | 2009-08-04 20:37:29 +0000 | [diff] [blame] | 117 | // CHECK-LP32: .long __ZN1A4foo1Ev |
| 118 | // CHECK-LP32: .long __ZN1A4foo2Ev |
Mike Stump | 2effeca | 2009-08-06 00:38:46 +0000 | [diff] [blame] | 119 | // CHECK-LP32: .long 4294967284 |
Mike Stump | e1be2b1 | 2009-08-06 21:49:36 +0000 | [diff] [blame] | 120 | // CHECK-LP32: .long __ZTI1A |
Mike Stump | 6f37633 | 2009-08-05 22:37:18 +0000 | [diff] [blame] | 121 | // CHECK-LP32: .long __ZN1C4bee1Ev |
| 122 | // CHECK-LP32: .long __ZN1C4bee2Ev |
Mike Stump | 8a12b56 | 2009-08-06 15:50:11 +0000 | [diff] [blame] | 123 | |
Mike Stump | 928f150 | 2009-08-07 19:00:50 +0000 | [diff] [blame] | 124 | // CHECK-LP32:__ZTV1F: |
| 125 | // CHECK-LP32: .space 4 |
Mike Stump | 57cf2f3 | 2009-08-07 21:54:03 +0000 | [diff] [blame^] | 126 | // CHECK-LP32: .long 8 |
Mike Stump | 928f150 | 2009-08-07 19:00:50 +0000 | [diff] [blame] | 127 | // CHECK-LP32: .space 4 |
Mike Stump | 8a12b56 | 2009-08-06 15:50:11 +0000 | [diff] [blame] | 128 | // CHECK-LP32: .space 4 |
Mike Stump | e1be2b1 | 2009-08-06 21:49:36 +0000 | [diff] [blame] | 129 | // CHECK-LP32: .long __ZTI1F |
Mike Stump | 70101ce | 2009-08-06 18:05:22 +0000 | [diff] [blame] | 130 | // CHECK-LP32: .long __ZN1D3booEv |
| 131 | // CHECK-LP32: .long __ZN1F3fooEv |
Mike Stump | 02cf1e2 | 2009-08-06 23:48:32 +0000 | [diff] [blame] | 132 | // CHECK-LP32: .space 4 |
| 133 | // CHECK-LP32: .space 4 |
| 134 | // CHECK-LP32: .space 4 |
| 135 | // CHECK-LP32: .space 4 |
| 136 | // CHECK-LP32: .space 4 |
Mike Stump | dac64a5 | 2009-08-06 22:02:55 +0000 | [diff] [blame] | 137 | // CHECK-LP32: .long 4294967288 |
Mike Stump | e1be2b1 | 2009-08-06 21:49:36 +0000 | [diff] [blame] | 138 | // CHECK-LP32: .long __ZTI1F |
Mike Stump | 8a12b56 | 2009-08-06 15:50:11 +0000 | [diff] [blame] | 139 | // CHECK-LP32: .long __ZN2D13barEv |
Mike Stump | 02cf1e2 | 2009-08-06 23:48:32 +0000 | [diff] [blame] | 140 | // CHECK-LP32: .long __ZN2D14bar2Ev |
| 141 | // CHECK-LP32: .long __ZN2D14bar3Ev |
| 142 | // CHECK-LP32: .long __ZN2D14bar4Ev |
| 143 | // CHECK-LP32: .long __ZN2D14bar5Ev |
Mike Stump | 8a12b56 | 2009-08-06 15:50:11 +0000 | [diff] [blame] | 144 | |
| 145 | // CHECK-LP64: __ZTV1F: |
Mike Stump | 928f150 | 2009-08-07 19:00:50 +0000 | [diff] [blame] | 146 | // CHECK-LP64: .space 8 |
Mike Stump | 57cf2f3 | 2009-08-07 21:54:03 +0000 | [diff] [blame^] | 147 | // CHECK-LP64: .quad 16 |
Mike Stump | 928f150 | 2009-08-07 19:00:50 +0000 | [diff] [blame] | 148 | // CHECK-LP64: .space 8 |
Mike Stump | 8a12b56 | 2009-08-06 15:50:11 +0000 | [diff] [blame] | 149 | // CHECK-LP64: .space 8 |
Mike Stump | e1be2b1 | 2009-08-06 21:49:36 +0000 | [diff] [blame] | 150 | // CHECK-LP64: .quad __ZTI1F |
Mike Stump | 70101ce | 2009-08-06 18:05:22 +0000 | [diff] [blame] | 151 | // CHECK-LP64: .quad __ZN1D3booEv |
| 152 | // CHECK-LP64: .quad __ZN1F3fooEv |
Mike Stump | 02cf1e2 | 2009-08-06 23:48:32 +0000 | [diff] [blame] | 153 | // CHECK-LP64: .space 8 |
| 154 | // CHECK-LP64: .space 8 |
| 155 | // CHECK-LP64: .space 8 |
| 156 | // CHECK-LP64: .space 8 |
| 157 | // CHECK-LP64: .space 8 |
Mike Stump | 636548d | 2009-08-06 21:53:24 +0000 | [diff] [blame] | 158 | // CHECK-LP64: .quad 18446744073709551600 |
| 159 | // CHECK-LP64: .quad __ZTI1F |
Mike Stump | 8a12b56 | 2009-08-06 15:50:11 +0000 | [diff] [blame] | 160 | // CHECK-LP64: .quad __ZN2D13barEv |
Mike Stump | 02cf1e2 | 2009-08-06 23:48:32 +0000 | [diff] [blame] | 161 | // CHECK-LP64: .quad __ZN2D14bar2Ev |
| 162 | // CHECK-LP64: .quad __ZN2D14bar3Ev |
| 163 | // CHECK-LP64: .quad __ZN2D14bar4Ev |
| 164 | // CHECK-LP64: .quad __ZN2D14bar5Ev |