blob: 1b78d89e8fc0086aaa996daba622137b8602b8a9 [file] [log] [blame]
Mike Stumpe1be2b12009-08-06 21:49:36 +00001// RUN: clang-cc -triple x86_64-apple-darwin -std=c++0x -O3 -S %s -o %t-64.s &&
Mike Stump06758d02009-08-04 20:37:29 +00002// RUN: FileCheck -check-prefix LP64 --input-file=%t-64.s %s &&
Mike Stumpe1be2b12009-08-06 21:49:36 +00003// RUN: clang-cc -triple i386-apple-darwin -std=c++0x -O3 -S %s -o %t-32.s &&
Mike Stump06758d02009-08-04 20:37:29 +00004// RUN: FileCheck -check-prefix LP32 -input-file=%t-32.s %s &&
5// RUN: true
Mike Stump3dee6ef2009-07-30 00:22:38 +00006
Mike Stump104ffaa2009-08-04 21:58:42 +00007struct B {
8 virtual void bar1();
9 virtual void bar2();
Mike Stump2effeca2009-08-06 00:38:46 +000010 int b;
Mike Stump104ffaa2009-08-04 21:58:42 +000011};
Mike Stump6f376332009-08-05 22:37:18 +000012void B::bar1() { }
13void B::bar2() { }
14
15struct C {
16 virtual void bee1();
17 virtual void bee2();
18};
19void C::bee1() { }
20void C::bee2() { }
Mike Stump104ffaa2009-08-04 21:58:42 +000021
Mike Stump2effeca2009-08-06 00:38:46 +000022struct D {
23 virtual void boo();
24};
25void D::boo() { }
Mike Stump104ffaa2009-08-04 21:58:42 +000026
Mike Stumpc5708d92009-08-06 14:12:47 +000027struct D1 {
28 virtual void bar();
Mike Stump02cf1e22009-08-06 23:48:32 +000029 virtual void bar2();
30 virtual void bar3();
31 virtual void bar4();
32 virtual void bar5();
Mike Stumpc5708d92009-08-06 14:12:47 +000033 void *d1;
34};
35void D1::bar() { }
36
37class F : virtual public D1, virtual public D {
38public:
39 virtual void foo();
40 void *f;
41};
42void F::foo() { }
43
44int j;
45void test2() {
46 F f;
47 static int sz = (char *)(&f.f) - (char *)(&f);
48 j = sz;
Mike Stump37148f42009-08-06 14:16:19 +000049 // FIXME: These should result in a frontend constant a la fold, no run time
50 // initializer
Mike Stumpc5708d92009-08-06 14:12:47 +000051 // CHECK-LP32: movl $4, __ZZ5test2vE2sz
52 // CHECK-LP64: movl $8, __ZZ5test2vE2sz(%rip)
53}
Mike Stump8a12b562009-08-06 15:50:11 +000054
Mike Stumpc5708d92009-08-06 14:12:47 +000055static_assert(sizeof(F) == sizeof(void*)*4, "invalid vbase size");
56
Mike Stump2effeca2009-08-06 00:38:46 +000057struct E {
58 int e;
59};
60
61static_assert (sizeof (C) == (sizeof(void *)), "vtable pointer layout");
62
Mike Stumpeb19fa92009-08-06 13:41:24 +000063class A : public E, public B, public C {
Mike Stump3dee6ef2009-07-30 00:22:38 +000064public:
Mike Stump06758d02009-08-04 20:37:29 +000065 virtual void foo1();
66 virtual void foo2();
67 A() { }
Mike Stump2effeca2009-08-06 00:38:46 +000068 int a;
69} *ap;
Mike Stump6f376332009-08-05 22:37:18 +000070void A::foo1() { }
71void A::foo2() { }
Mike Stump3dee6ef2009-07-30 00:22:38 +000072
Mike Stump06758d02009-08-04 20:37:29 +000073int main() {
74 A a;
Mike Stump26899b02009-08-05 22:48:36 +000075 B b;
Mike Stump2effeca2009-08-06 00:38:46 +000076 ap->e = 1;
77 ap->b = 2;
Mike Stump06758d02009-08-04 20:37:29 +000078}
79
Mike Stump2effeca2009-08-06 00:38:46 +000080// 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 Stump26899b02009-08-05 22:48:36 +000088// CHECK-LP64: __ZTV1B:
89// CHECK-LP64: .space 8
Mike Stumpe1be2b12009-08-06 21:49:36 +000090// CHECK-LP64: .quad __ZTI1B
Mike Stump26899b02009-08-05 22:48:36 +000091// CHECK-LP64: .quad __ZN1B4bar1Ev
92// CHECK-LP64: .quad __ZN1B4bar2Ev
93
94// CHECK-LP32: __ZTV1B:
95// CHECK-LP32: .space 4
Mike Stumpe1be2b12009-08-06 21:49:36 +000096// CHECK-LP32: .long __ZTI1B
Mike Stump26899b02009-08-05 22:48:36 +000097// CHECK-LP32: .long __ZN1B4bar1Ev
98// CHECK-LP32: .long __ZN1B4bar2Ev
99
Mike Stump06758d02009-08-04 20:37:29 +0000100// CHECK-LP64: __ZTV1A:
101// CHECK-LP64: .space 8
Mike Stumpe1be2b12009-08-06 21:49:36 +0000102// CHECK-LP64: .quad __ZTI1A
Mike Stump104ffaa2009-08-04 21:58:42 +0000103// CHECK-LP64: .quad __ZN1B4bar1Ev
104// CHECK-LP64: .quad __ZN1B4bar2Ev
Mike Stump06758d02009-08-04 20:37:29 +0000105// CHECK-LP64: .quad __ZN1A4foo1Ev
106// CHECK-LP64: .quad __ZN1A4foo2Ev
Mike Stump2effeca2009-08-06 00:38:46 +0000107// CHECK-LP64: .quad 18446744073709551600
Mike Stumpe1be2b12009-08-06 21:49:36 +0000108// CHECK-LP64: .quad __ZTI1A
Mike Stump6f376332009-08-05 22:37:18 +0000109// CHECK-LP64: .quad __ZN1C4bee1Ev
110// CHECK-LP64: .quad __ZN1C4bee2Ev
Mike Stump06758d02009-08-04 20:37:29 +0000111
112// CHECK-LP32: __ZTV1A:
113// CHECK-LP32: .space 4
Mike Stumpe1be2b12009-08-06 21:49:36 +0000114// CHECK-LP32: .long __ZTI1A
Mike Stump104ffaa2009-08-04 21:58:42 +0000115// CHECK-LP32: .long __ZN1B4bar1Ev
116// CHECK-LP32: .long __ZN1B4bar2Ev
Mike Stump06758d02009-08-04 20:37:29 +0000117// CHECK-LP32: .long __ZN1A4foo1Ev
118// CHECK-LP32: .long __ZN1A4foo2Ev
Mike Stump2effeca2009-08-06 00:38:46 +0000119// CHECK-LP32: .long 4294967284
Mike Stumpe1be2b12009-08-06 21:49:36 +0000120// CHECK-LP32: .long __ZTI1A
Mike Stump6f376332009-08-05 22:37:18 +0000121// CHECK-LP32: .long __ZN1C4bee1Ev
122// CHECK-LP32: .long __ZN1C4bee2Ev
Mike Stump8a12b562009-08-06 15:50:11 +0000123
Mike Stump928f1502009-08-07 19:00:50 +0000124// CHECK-LP32:__ZTV1F:
125// CHECK-LP32: .space 4
Mike Stump57cf2f32009-08-07 21:54:03 +0000126// CHECK-LP32: .long 8
Mike Stump928f1502009-08-07 19:00:50 +0000127// CHECK-LP32: .space 4
Mike Stump8a12b562009-08-06 15:50:11 +0000128// CHECK-LP32: .space 4
Mike Stumpe1be2b12009-08-06 21:49:36 +0000129// CHECK-LP32: .long __ZTI1F
Mike Stump70101ce2009-08-06 18:05:22 +0000130// CHECK-LP32: .long __ZN1D3booEv
131// CHECK-LP32: .long __ZN1F3fooEv
Mike Stump02cf1e22009-08-06 23:48:32 +0000132// 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 Stumpdac64a52009-08-06 22:02:55 +0000137// CHECK-LP32: .long 4294967288
Mike Stumpe1be2b12009-08-06 21:49:36 +0000138// CHECK-LP32: .long __ZTI1F
Mike Stump8a12b562009-08-06 15:50:11 +0000139// CHECK-LP32: .long __ZN2D13barEv
Mike Stump02cf1e22009-08-06 23:48:32 +0000140// CHECK-LP32: .long __ZN2D14bar2Ev
141// CHECK-LP32: .long __ZN2D14bar3Ev
142// CHECK-LP32: .long __ZN2D14bar4Ev
143// CHECK-LP32: .long __ZN2D14bar5Ev
Mike Stump8a12b562009-08-06 15:50:11 +0000144
145// CHECK-LP64: __ZTV1F:
Mike Stump928f1502009-08-07 19:00:50 +0000146// CHECK-LP64: .space 8
Mike Stump57cf2f32009-08-07 21:54:03 +0000147// CHECK-LP64: .quad 16
Mike Stump928f1502009-08-07 19:00:50 +0000148// CHECK-LP64: .space 8
Mike Stump8a12b562009-08-06 15:50:11 +0000149// CHECK-LP64: .space 8
Mike Stumpe1be2b12009-08-06 21:49:36 +0000150// CHECK-LP64: .quad __ZTI1F
Mike Stump70101ce2009-08-06 18:05:22 +0000151// CHECK-LP64: .quad __ZN1D3booEv
152// CHECK-LP64: .quad __ZN1F3fooEv
Mike Stump02cf1e22009-08-06 23:48:32 +0000153// 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 Stump636548d2009-08-06 21:53:24 +0000158// CHECK-LP64: .quad 18446744073709551600
159// CHECK-LP64: .quad __ZTI1F
Mike Stump8a12b562009-08-06 15:50:11 +0000160// CHECK-LP64: .quad __ZN2D13barEv
Mike Stump02cf1e22009-08-06 23:48:32 +0000161// CHECK-LP64: .quad __ZN2D14bar2Ev
162// CHECK-LP64: .quad __ZN2D14bar3Ev
163// CHECK-LP64: .quad __ZN2D14bar4Ev
164// CHECK-LP64: .quad __ZN2D14bar5Ev