blob: f462b0e693e4e634f8260ea86293d6f652fe6973 [file] [log] [blame]
Mike Stumpc5708d92009-08-06 14:12:47 +00001// RUN: clang-cc -triple x86_64-apple-darwin -frtti=0 -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 Stumpc5708d92009-08-06 14:12:47 +00003// RUN: clang-cc -triple i386-apple-darwin -frtti=0 -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();
29 void *d1;
30};
31void D1::bar() { }
32
33class F : virtual public D1, virtual public D {
34public:
35 virtual void foo();
36 void *f;
37};
38void F::foo() { }
39
40int j;
41void test2() {
42 F f;
43 static int sz = (char *)(&f.f) - (char *)(&f);
44 j = sz;
Mike Stump37148f42009-08-06 14:16:19 +000045 // FIXME: These should result in a frontend constant a la fold, no run time
46 // initializer
Mike Stumpc5708d92009-08-06 14:12:47 +000047 // CHECK-LP32: movl $4, __ZZ5test2vE2sz
48 // CHECK-LP64: movl $8, __ZZ5test2vE2sz(%rip)
49}
Mike Stump8a12b562009-08-06 15:50:11 +000050
Mike Stumpc5708d92009-08-06 14:12:47 +000051static_assert(sizeof(F) == sizeof(void*)*4, "invalid vbase size");
52
Mike Stump2effeca2009-08-06 00:38:46 +000053struct E {
54 int e;
55};
56
57static_assert (sizeof (C) == (sizeof(void *)), "vtable pointer layout");
58
Mike Stumpeb19fa92009-08-06 13:41:24 +000059class A : public E, public B, public C {
Mike Stump3dee6ef2009-07-30 00:22:38 +000060public:
Mike Stump06758d02009-08-04 20:37:29 +000061 virtual void foo1();
62 virtual void foo2();
63 A() { }
Mike Stump2effeca2009-08-06 00:38:46 +000064 int a;
65} *ap;
Mike Stump6f376332009-08-05 22:37:18 +000066void A::foo1() { }
67void A::foo2() { }
Mike Stump3dee6ef2009-07-30 00:22:38 +000068
Mike Stump06758d02009-08-04 20:37:29 +000069int main() {
70 A a;
Mike Stump26899b02009-08-05 22:48:36 +000071 B b;
Mike Stump2effeca2009-08-06 00:38:46 +000072 ap->e = 1;
73 ap->b = 2;
Mike Stump06758d02009-08-04 20:37:29 +000074}
75
Mike Stump2effeca2009-08-06 00:38:46 +000076// 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 Stump26899b02009-08-05 22:48:36 +000084// 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 Stump06758d02009-08-04 20:37:29 +000096// CHECK-LP64: __ZTV1A:
97// CHECK-LP64: .space 8
98// CHECK-LP64: .space 8
Mike Stump104ffaa2009-08-04 21:58:42 +000099// CHECK-LP64: .quad __ZN1B4bar1Ev
100// CHECK-LP64: .quad __ZN1B4bar2Ev
Mike Stump06758d02009-08-04 20:37:29 +0000101// CHECK-LP64: .quad __ZN1A4foo1Ev
102// CHECK-LP64: .quad __ZN1A4foo2Ev
Mike Stump2effeca2009-08-06 00:38:46 +0000103// CHECK-LP64: .quad 18446744073709551600
Mike Stump6f376332009-08-05 22:37:18 +0000104// CHECK-LP64: .space 8
105// CHECK-LP64: .quad __ZN1C4bee1Ev
106// CHECK-LP64: .quad __ZN1C4bee2Ev
Mike Stump06758d02009-08-04 20:37:29 +0000107
108// CHECK-LP32: __ZTV1A:
109// CHECK-LP32: .space 4
110// CHECK-LP32: .space 4
Mike Stump104ffaa2009-08-04 21:58:42 +0000111// CHECK-LP32: .long __ZN1B4bar1Ev
112// CHECK-LP32: .long __ZN1B4bar2Ev
Mike Stump06758d02009-08-04 20:37:29 +0000113// CHECK-LP32: .long __ZN1A4foo1Ev
114// CHECK-LP32: .long __ZN1A4foo2Ev
Mike Stump2effeca2009-08-06 00:38:46 +0000115// CHECK-LP32: .long 4294967284
Mike Stump6f376332009-08-05 22:37:18 +0000116// CHECK-LP32: .space 4
117// CHECK-LP32: .long __ZN1C4bee1Ev
118// CHECK-LP32: .long __ZN1C4bee2Ev
Mike Stump8a12b562009-08-06 15:50:11 +0000119
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
126// CHECK-LP32 .long __ZN1D3booEv
127// CHECK-LP32 .long __ZN1F3fooEv
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
139// CHECK-LP64 .quad __ZN1D3booEv
140// CHECK-LP64 .quad __ZN1F3fooEv
141// CHECK-LP64 .space 8
142// CHECK-LP64 .space -16
143// CHECK-LP64 .space 8
144// CHECK-LP64: .quad __ZN2D13barEv
145