2014-01-15 03:35:09 +08:00
|
|
|
// RUN: %clang_cc1 %s -fno-rtti -triple=i386-pc-win32 -emit-llvm -fdump-vtable-layouts -o %t.ll > %t
|
2013-11-09 05:28:00 +08:00
|
|
|
// RUN: FileCheck --check-prefix=EMITS-VFTABLE %s < %t.ll
|
|
|
|
// RUN: FileCheck --check-prefix=NO-VFTABLE %s < %t.ll
|
2014-03-21 19:39:24 +08:00
|
|
|
// RUN: FileCheck %s < %t
|
2013-07-30 17:46:19 +08:00
|
|
|
|
2013-01-21 21:02:41 +08:00
|
|
|
struct A {
|
2014-03-21 19:39:24 +08:00
|
|
|
// CHECK-LABEL: VFTable for 'A' (3 entries)
|
|
|
|
// CHECK-NEXT: 0 | void A::f()
|
|
|
|
// CHECK-NEXT: 1 | void A::g()
|
|
|
|
// CHECK-NEXT: 2 | void A::h()
|
|
|
|
// CHECK-LABEL: VFTable indices for 'A' (3 entries)
|
|
|
|
// CHECK-NEXT: 0 | void A::f()
|
|
|
|
// CHECK-NEXT: 1 | void A::g()
|
|
|
|
// CHECK-NEXT: 2 | void A::h()
|
2013-07-30 17:46:19 +08:00
|
|
|
|
2013-01-21 21:02:41 +08:00
|
|
|
virtual void f();
|
|
|
|
virtual void g();
|
|
|
|
virtual void h();
|
|
|
|
int ia;
|
|
|
|
};
|
2013-05-30 00:18:30 +08:00
|
|
|
A a;
|
2018-03-17 04:36:49 +08:00
|
|
|
// EMITS-VFTABLE-DAG: @"??_7A@@6B@" = linkonce_odr unnamed_addr constant { [3 x i8*] }
|
2014-03-21 19:39:24 +08:00
|
|
|
void use(A *obj) { obj->f(); }
|
2013-01-21 21:02:41 +08:00
|
|
|
|
|
|
|
struct B : A {
|
2014-03-21 19:39:24 +08:00
|
|
|
// CHECK-LABEL: VFTable for 'A' in 'B' (5 entries)
|
|
|
|
// CHECK-NEXT: 0 | void B::f()
|
|
|
|
// CHECK-NEXT: 1 | void A::g()
|
|
|
|
// CHECK-NEXT: 2 | void A::h()
|
|
|
|
// CHECK-NEXT: 3 | void B::i()
|
|
|
|
// CHECK-NEXT: 4 | void B::j()
|
|
|
|
// CHECK-LABEL: VFTable indices for 'B' (3 entries)
|
|
|
|
// CHECK-NEXT: 0 | void B::f()
|
|
|
|
// CHECK-NEXT: 3 | void B::i()
|
|
|
|
// CHECK-NEXT: 4 | void B::j()
|
2013-07-30 17:46:19 +08:00
|
|
|
|
2013-01-21 21:02:41 +08:00
|
|
|
virtual void f(); // overrides A::f()
|
|
|
|
virtual void i();
|
|
|
|
virtual void j();
|
|
|
|
};
|
2013-05-30 00:18:30 +08:00
|
|
|
B b;
|
2018-03-17 04:36:49 +08:00
|
|
|
// EMITS-VFTABLE-DAG: @"??_7B@@6B@" = linkonce_odr unnamed_addr constant { [5 x i8*] }
|
2014-03-21 19:39:24 +08:00
|
|
|
void use(B *obj) { obj->f(); }
|
2013-01-21 21:02:41 +08:00
|
|
|
|
|
|
|
struct C {
|
2014-03-21 19:39:24 +08:00
|
|
|
// CHECK-LABEL: VFTable for 'C' (2 entries)
|
|
|
|
// CHECK-NEXT: 0 | C::~C() [scalar deleting]
|
|
|
|
// CHECK-NEXT: 1 | void C::f()
|
|
|
|
// CHECK-LABEL: VFTable indices for 'C' (2 entries).
|
|
|
|
// CHECK-NEXT: 0 | C::~C() [scalar deleting]
|
|
|
|
// CHECK-NEXT: 1 | void C::f()
|
2013-07-30 17:46:19 +08:00
|
|
|
|
|
|
|
virtual ~C();
|
2013-01-21 21:02:41 +08:00
|
|
|
virtual void f();
|
|
|
|
};
|
|
|
|
void C::f() {}
|
2018-03-17 04:36:49 +08:00
|
|
|
// NO-VFTABLE-NOT: @"??_7C@@6B@"
|
2014-03-21 19:39:24 +08:00
|
|
|
void use(C *obj) { obj->f(); }
|
2013-01-21 21:02:41 +08:00
|
|
|
|
|
|
|
struct D {
|
2014-03-21 19:39:24 +08:00
|
|
|
// CHECK-LABEL: VFTable for 'D' (2 entries)
|
|
|
|
// CHECK-NEXT: 0 | void D::f()
|
|
|
|
// CHECK-NEXT: 1 | D::~D() [scalar deleting]
|
|
|
|
// CHECK-LABEL: VFTable indices for 'D' (2 entries)
|
|
|
|
// CHECK-NEXT: 0 | void D::f()
|
|
|
|
// CHECK-NEXT: 1 | D::~D() [scalar deleting]
|
2013-07-30 17:46:19 +08:00
|
|
|
|
|
|
|
virtual void f();
|
2013-01-21 21:02:41 +08:00
|
|
|
virtual ~D();
|
|
|
|
};
|
2013-05-30 00:18:30 +08:00
|
|
|
D d;
|
2018-03-17 04:36:49 +08:00
|
|
|
// EMITS-VFTABLE-DAG: @"??_7D@@6B@" = linkonce_odr unnamed_addr constant { [2 x i8*] }
|
2014-03-21 19:39:24 +08:00
|
|
|
void use(D *obj) { obj->f(); }
|
2013-01-21 21:02:41 +08:00
|
|
|
|
|
|
|
struct E : A {
|
2014-03-21 19:39:24 +08:00
|
|
|
// CHECK-LABEL: VFTable for 'A' in 'E' (5 entries)
|
|
|
|
// CHECK-NEXT: 0 | void A::f()
|
|
|
|
// CHECK-NEXT: 1 | void A::g()
|
|
|
|
// CHECK-NEXT: 2 | void A::h()
|
|
|
|
// CHECK-NEXT: 3 | E::~E() [scalar deleting]
|
|
|
|
// CHECK-NEXT: 4 | void E::i()
|
|
|
|
// CHECK-LABEL: VFTable indices for 'E' (2 entries).
|
|
|
|
// CHECK-NEXT: 3 | E::~E() [scalar deleting]
|
|
|
|
// CHECK-NEXT: 4 | void E::i()
|
2013-07-30 17:46:19 +08:00
|
|
|
|
2013-05-30 00:18:30 +08:00
|
|
|
// ~E would be the key method, but it isn't used, and MS ABI has no key
|
|
|
|
// methods.
|
2013-01-21 21:02:41 +08:00
|
|
|
virtual ~E();
|
|
|
|
virtual void i();
|
|
|
|
};
|
|
|
|
void E::i() {}
|
2018-03-17 04:36:49 +08:00
|
|
|
// NO-VFTABLE-NOT: @"??_7E@@6B@"
|
2014-03-21 19:39:24 +08:00
|
|
|
void use(E *obj) { obj->i(); }
|
2013-01-21 21:02:41 +08:00
|
|
|
|
|
|
|
struct F : A {
|
2014-03-21 19:39:24 +08:00
|
|
|
// CHECK-LABEL: VFTable for 'A' in 'F' (5 entries)
|
|
|
|
// CHECK-NEXT: 0 | void A::f()
|
|
|
|
// CHECK-NEXT: 1 | void A::g()
|
|
|
|
// CHECK-NEXT: 2 | void A::h()
|
|
|
|
// CHECK-NEXT: 3 | void F::i()
|
|
|
|
// CHECK-NEXT: 4 | F::~F() [scalar deleting]
|
|
|
|
// CHECK-LABEL: VFTable indices for 'F' (2 entries).
|
|
|
|
// CHECK-NEXT: 3 | void F::i()
|
|
|
|
// CHECK-NEXT: 4 | F::~F() [scalar deleting]
|
2013-07-30 17:46:19 +08:00
|
|
|
|
2013-01-21 21:02:41 +08:00
|
|
|
virtual void i();
|
|
|
|
virtual ~F();
|
|
|
|
};
|
2013-05-30 00:18:30 +08:00
|
|
|
F f;
|
2018-03-17 04:36:49 +08:00
|
|
|
// EMITS-VFTABLE-DAG: @"??_7F@@6B@" = linkonce_odr unnamed_addr constant { [5 x i8*] }
|
2014-03-21 19:39:24 +08:00
|
|
|
void use(F *obj) { obj->i(); }
|
2013-01-21 21:02:41 +08:00
|
|
|
|
|
|
|
struct G : E {
|
2014-03-21 19:39:24 +08:00
|
|
|
// CHECK-LABEL: VFTable for 'A' in 'E' in 'G' (6 entries)
|
|
|
|
// CHECK-NEXT: 0 | void G::f()
|
|
|
|
// CHECK-NEXT: 1 | void A::g()
|
|
|
|
// CHECK-NEXT: 2 | void A::h()
|
|
|
|
// CHECK-NEXT: 3 | G::~G() [scalar deleting]
|
|
|
|
// CHECK-NEXT: 4 | void E::i()
|
|
|
|
// CHECK-NEXT: 5 | void G::j()
|
|
|
|
// CHECK-LABEL: VFTable indices for 'G' (3 entries).
|
|
|
|
// CHECK-NEXT: 0 | void G::f()
|
|
|
|
// CHECK-NEXT: 3 | G::~G() [scalar deleting]
|
|
|
|
// CHECK-NEXT: 5 | void G::j()
|
2013-07-30 17:46:19 +08:00
|
|
|
|
2013-01-21 21:02:41 +08:00
|
|
|
virtual void f(); // overrides A::f()
|
|
|
|
virtual ~G();
|
|
|
|
virtual void j();
|
|
|
|
};
|
|
|
|
void G::j() {}
|
2018-03-17 04:36:49 +08:00
|
|
|
// NO-VFTABLE-NOT: @"??_7G@@6B@"
|
2014-03-21 19:39:24 +08:00
|
|
|
void use(G *obj) { obj->j(); }
|
2013-05-30 00:51:17 +08:00
|
|
|
|
|
|
|
// Test that the usual Itanium-style key method does not emit a vtable.
|
|
|
|
struct H {
|
|
|
|
virtual void f();
|
|
|
|
};
|
|
|
|
void H::f() {}
|
2018-03-17 04:36:49 +08:00
|
|
|
// NO-VFTABLE-NOT: @"??_7H@@6B@"
|
2013-07-30 17:46:19 +08:00
|
|
|
|
|
|
|
struct Empty { };
|
|
|
|
|
|
|
|
struct I : Empty {
|
2014-03-21 19:39:24 +08:00
|
|
|
// CHECK-LABEL: VFTable for 'I' (2 entries)
|
|
|
|
// CHECK-NEXT: 0 | void I::f()
|
|
|
|
// CHECK-NEXT: 1 | void I::g()
|
2013-07-30 17:46:19 +08:00
|
|
|
virtual void f();
|
|
|
|
virtual void g();
|
|
|
|
};
|
|
|
|
|
|
|
|
I i;
|
2014-03-21 19:39:24 +08:00
|
|
|
void use(I *obj) { obj->f(); }
|
2013-10-06 23:31:37 +08:00
|
|
|
|
|
|
|
struct J {
|
2014-03-21 19:39:24 +08:00
|
|
|
// CHECK-LABEL: VFTable for 'J' (6 entries)
|
|
|
|
// CHECK-NEXT: 0 | void J::foo(long)
|
|
|
|
// CHECK-NEXT: 1 | void J::foo(int)
|
|
|
|
// CHECK-NEXT: 2 | void J::foo(short)
|
|
|
|
// CHECK-NEXT: 3 | void J::bar(long)
|
|
|
|
// CHECK-NEXT: 4 | void J::bar(int)
|
|
|
|
// CHECK-NEXT: 5 | void J::bar(short)
|
2013-10-06 23:31:37 +08:00
|
|
|
virtual void foo(short);
|
|
|
|
virtual void bar(short);
|
|
|
|
virtual void foo(int);
|
|
|
|
virtual void bar(int);
|
|
|
|
virtual void foo(long);
|
|
|
|
virtual void bar(long);
|
|
|
|
};
|
|
|
|
|
|
|
|
J j;
|
2014-03-21 19:39:24 +08:00
|
|
|
void use(J *obj) { obj->foo(42); }
|
2013-10-06 23:31:37 +08:00
|
|
|
|
|
|
|
struct K : J {
|
2014-03-21 19:39:24 +08:00
|
|
|
// CHECK-LABEL: VFTable for 'J' in 'K' (9 entries)
|
|
|
|
// CHECK-NEXT: 0 | void J::foo(long)
|
|
|
|
// CHECK-NEXT: 1 | void J::foo(int)
|
|
|
|
// CHECK-NEXT: 2 | void J::foo(short)
|
|
|
|
// CHECK-NEXT: 3 | void J::bar(long)
|
|
|
|
// CHECK-NEXT: 4 | void J::bar(int)
|
|
|
|
// CHECK-NEXT: 5 | void J::bar(short)
|
|
|
|
// CHECK-NEXT: 6 | void K::bar(double)
|
|
|
|
// CHECK-NEXT: 7 | void K::bar(float)
|
|
|
|
// CHECK-NEXT: 8 | void K::foo(float)
|
2013-10-06 23:31:37 +08:00
|
|
|
virtual void bar(float);
|
|
|
|
virtual void foo(float);
|
|
|
|
virtual void bar(double);
|
|
|
|
};
|
|
|
|
|
|
|
|
K k;
|
2014-03-21 19:39:24 +08:00
|
|
|
void use(K *obj) { obj->foo(42.0f); }
|
2013-10-06 23:31:37 +08:00
|
|
|
|
|
|
|
struct L : J {
|
2014-03-21 19:39:24 +08:00
|
|
|
// CHECK-LABEL: VFTable for 'J' in 'L' (9 entries)
|
|
|
|
// CHECK-NEXT: 0 | void J::foo(long)
|
|
|
|
// CHECK-NEXT: 1 | void L::foo(int)
|
|
|
|
// CHECK-NEXT: 2 | void J::foo(short)
|
|
|
|
// CHECK-NEXT: 3 | void J::bar(long)
|
|
|
|
// CHECK-NEXT: 4 | void J::bar(int)
|
|
|
|
// CHECK-NEXT: 5 | void J::bar(short)
|
|
|
|
// CHECK-NEXT: 6 | void L::foo(float)
|
|
|
|
// CHECK-NEXT: 7 | void L::bar(double)
|
|
|
|
// CHECK-NEXT: 8 | void L::bar(float)
|
2013-10-06 23:31:37 +08:00
|
|
|
|
|
|
|
// This case is interesting. Since the J::foo(int) override is the first method in
|
|
|
|
// the class, foo(float) precedes the bar(double) and bar(float) in the vftable.
|
|
|
|
virtual void foo(int);
|
|
|
|
virtual void bar(float);
|
|
|
|
virtual void foo(float);
|
|
|
|
virtual void bar(double);
|
|
|
|
};
|
|
|
|
|
|
|
|
L l;
|
2014-03-21 19:39:24 +08:00
|
|
|
void use(L *obj) { obj->foo(42.0f); }
|
2013-10-06 23:31:37 +08:00
|
|
|
|
|
|
|
struct M : J {
|
2014-03-21 19:39:24 +08:00
|
|
|
// CHECK-LABEL: VFTable for 'J' in 'M' (11 entries)
|
|
|
|
// CHECK-NEXT: 0 | void J::foo(long)
|
|
|
|
// CHECK-NEXT: 1 | void M::foo(int)
|
|
|
|
// CHECK-NEXT: 2 | void J::foo(short)
|
|
|
|
// CHECK-NEXT: 3 | void J::bar(long)
|
|
|
|
// CHECK-NEXT: 4 | void J::bar(int)
|
|
|
|
// CHECK-NEXT: 5 | void J::bar(short)
|
|
|
|
// CHECK-NEXT: 6 | void M::foo(float)
|
|
|
|
// CHECK-NEXT: 7 | void M::spam(long)
|
|
|
|
// CHECK-NEXT: 8 | void M::spam(int)
|
|
|
|
// CHECK-NEXT: 9 | void M::bar(double)
|
|
|
|
// CHECK-NEXT: 10 | void M::bar(float)
|
2013-10-06 23:31:37 +08:00
|
|
|
|
|
|
|
virtual void foo(int);
|
|
|
|
virtual void spam(int);
|
|
|
|
virtual void bar(float);
|
|
|
|
virtual void bar(double);
|
|
|
|
virtual void foo(float);
|
|
|
|
virtual void spam(long);
|
|
|
|
};
|
|
|
|
|
|
|
|
M m;
|
2014-03-21 19:39:24 +08:00
|
|
|
void use(M *obj) { obj->foo(42.0f); }
|
2013-10-06 23:31:37 +08:00
|
|
|
|
|
|
|
struct N {
|
2014-03-21 19:39:24 +08:00
|
|
|
// CHECK-LABEL: VFTable for 'N' (4 entries)
|
|
|
|
// CHECK-NEXT: 0 | void N::operator+(int)
|
|
|
|
// CHECK-NEXT: 1 | void N::operator+(short)
|
|
|
|
// CHECK-NEXT: 2 | void N::operator*(int)
|
|
|
|
// CHECK-NEXT: 3 | void N::operator*(short)
|
2013-10-06 23:31:37 +08:00
|
|
|
virtual void operator+(short);
|
|
|
|
virtual void operator*(short);
|
|
|
|
virtual void operator+(int);
|
|
|
|
virtual void operator*(int);
|
|
|
|
};
|
|
|
|
|
|
|
|
N n;
|
2014-03-21 19:39:24 +08:00
|
|
|
void use(N *obj) { obj->operator+(42); }
|
2013-12-21 05:44:05 +08:00
|
|
|
|
2013-12-28 03:43:59 +08:00
|
|
|
struct O { virtual A *f(); };
|
|
|
|
struct P : O { virtual B *f(); };
|
2013-12-21 05:44:05 +08:00
|
|
|
P p;
|
2014-03-21 19:39:24 +08:00
|
|
|
void use(O *obj) { obj->f(); }
|
|
|
|
void use(P *obj) { obj->f(); }
|
|
|
|
// CHECK-LABEL: VFTable for 'O' (1 entry)
|
|
|
|
// CHECK-NEXT: 0 | A *O::f()
|
2014-02-20 06:06:10 +08:00
|
|
|
|
2014-03-21 19:39:24 +08:00
|
|
|
// CHECK-LABEL: VFTable for 'O' in 'P' (1 entry)
|
|
|
|
// CHECK-NEXT: 0 | B *P::f()
|
2014-02-28 03:40:09 +08:00
|
|
|
|
2014-02-20 06:06:10 +08:00
|
|
|
struct Q {
|
2014-03-21 19:39:24 +08:00
|
|
|
// CHECK-LABEL: VFTable for 'Q' (2 entries)
|
|
|
|
// CHECK-NEXT: 0 | void Q::foo(int)
|
|
|
|
// CHECK-NEXT: 1 | void Q::bar(int)
|
2014-02-20 06:06:10 +08:00
|
|
|
void foo(short);
|
|
|
|
void bar(short);
|
|
|
|
virtual void bar(int);
|
|
|
|
virtual void foo(int);
|
|
|
|
};
|
|
|
|
|
|
|
|
Q q;
|
2014-03-21 19:39:24 +08:00
|
|
|
void use(Q *obj) { obj->foo(42); }
|
2014-02-20 06:06:10 +08:00
|
|
|
|
|
|
|
// Inherited non-virtual overloads don't participate in the ordering.
|
|
|
|
struct R : Q {
|
2014-03-21 19:39:24 +08:00
|
|
|
// CHECK-LABEL: VFTable for 'Q' in 'R' (4 entries)
|
|
|
|
// CHECK-NEXT: 0 | void Q::foo(int)
|
|
|
|
// CHECK-NEXT: 1 | void Q::bar(int)
|
|
|
|
// CHECK-NEXT: 2 | void R::bar(long)
|
|
|
|
// CHECK-NEXT: 3 | void R::foo(long)
|
2014-02-20 06:06:10 +08:00
|
|
|
virtual void bar(long);
|
|
|
|
virtual void foo(long);
|
|
|
|
};
|
|
|
|
|
|
|
|
R r;
|
2014-03-21 19:39:24 +08:00
|
|
|
void use(R *obj) { obj->foo(42l); }
|
2014-10-03 16:03:23 +08:00
|
|
|
|
|
|
|
struct S {
|
|
|
|
// CHECK-LABEL: VFTable for 'S' (1 entry).
|
|
|
|
// CHECK-NEXT: 0 | void S::f() [deleted]
|
|
|
|
virtual void f() = delete;
|
|
|
|
S();
|
2018-03-17 04:36:49 +08:00
|
|
|
// EMITS-VFTABLE-DAG: @"??_7S@@6B@" = linkonce_odr unnamed_addr constant { [1 x i8*] } { [1 x i8*] [i8* bitcast (void ()* @_purecall to i8*)] }
|
2014-10-03 16:03:23 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
S::S() {}
|
2015-11-19 08:03:54 +08:00
|
|
|
|
|
|
|
struct T {
|
|
|
|
struct U {};
|
|
|
|
};
|
|
|
|
struct V : T {
|
|
|
|
// CHECK-LABEL: VFTable for 'V' (2 entries).
|
|
|
|
// CHECK-NEXT: 0 | void V::U()
|
|
|
|
// CHECK-NEXT: 1 | void V::f()
|
|
|
|
using T::U;
|
|
|
|
virtual void f();
|
|
|
|
virtual void U();
|
|
|
|
V();
|
|
|
|
};
|
|
|
|
|
|
|
|
V::V() {}
|