2014-02-06 01:27:08 +08:00
|
|
|
// RUN: %clang_cc1 -Wno-microsoft -fno-rtti -std=c++11 -emit-llvm %s -o - -triple=i386-pc-win32 | FileCheck %s
|
|
|
|
|
|
|
|
struct U;
|
|
|
|
static_assert(sizeof(void (U::*)()) == 2 * sizeof(void*) + 2 * sizeof(int), "");
|
|
|
|
|
|
|
|
struct A { int a; };
|
|
|
|
struct B { int b; };
|
2014-02-07 03:14:16 +08:00
|
|
|
struct I { union { struct { int a, b; }; }; };
|
2014-02-06 01:27:08 +08:00
|
|
|
|
|
|
|
struct S { int a, b; void f(); virtual void g(); };
|
|
|
|
struct M : A, B { int a, b; void f(); virtual void g(); };
|
|
|
|
struct V : virtual A { int a, b; void f(); virtual void g(); };
|
|
|
|
struct U { int a, b; void f(); virtual void g(); };
|
|
|
|
|
|
|
|
struct C { virtual void f(); };
|
|
|
|
struct D { virtual void g(); };
|
|
|
|
struct O : C, D { virtual void g(); }; // override of non-primary
|
|
|
|
|
|
|
|
// Test data member pointers.
|
|
|
|
template <typename T, int T::*F>
|
|
|
|
int ReadField(T &o) {
|
|
|
|
return F ? o.*F : 0;
|
|
|
|
}
|
|
|
|
|
2014-02-08 09:15:37 +08:00
|
|
|
// Redeclare some of the classes so that the implicit attribute goes on the most
|
|
|
|
// recent redeclaration rather than the definition.
|
|
|
|
struct V;
|
|
|
|
|
2014-02-06 01:27:08 +08:00
|
|
|
void ReadFields() {
|
|
|
|
A a;
|
2014-02-07 03:14:16 +08:00
|
|
|
I i;
|
2014-02-06 01:27:08 +08:00
|
|
|
S s;
|
|
|
|
M m;
|
|
|
|
V v;
|
|
|
|
U u;
|
|
|
|
ReadField<S, &S::a>(s);
|
|
|
|
ReadField<M, &M::a>(m);
|
|
|
|
ReadField<V, &V::a>(v);
|
|
|
|
ReadField<U, &U::a>(u);
|
|
|
|
ReadField<S, &S::b>(s);
|
|
|
|
ReadField<M, &M::b>(m);
|
|
|
|
ReadField<V, &V::b>(v);
|
|
|
|
ReadField<U, &U::b>(u);
|
|
|
|
ReadField<S, nullptr>(s);
|
|
|
|
ReadField<M, nullptr>(m);
|
|
|
|
ReadField<V, nullptr>(v);
|
|
|
|
ReadField<U, nullptr>(u);
|
|
|
|
|
|
|
|
// Non-polymorphic null data memptr vs first field memptr.
|
|
|
|
ReadField<A, &A::a>(a);
|
|
|
|
ReadField<A, nullptr>(a);
|
2014-02-07 03:14:16 +08:00
|
|
|
|
|
|
|
// Indirect fields injected from anonymous unions and structs
|
|
|
|
ReadField<I, &I::a>(i);
|
|
|
|
ReadField<I, &I::b>(i);
|
2014-02-06 01:27:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: define {{.*}}ReadFields
|
2018-03-17 04:36:49 +08:00
|
|
|
// CHECK: call {{.*}} @"??$ReadField@US@@$03@@YAHAAUS@@@Z"
|
|
|
|
// CHECK: call {{.*}} @"??$ReadField@UM@@$0M@@@YAHAAUM@@@Z"
|
|
|
|
// CHECK: call {{.*}} @"??$ReadField@UV@@$F7A@@@YAHAAUV@@@Z"
|
|
|
|
// CHECK: call {{.*}} @"??$ReadField@UU@@$G3A@A@@@YAHAAUU@@@Z"
|
|
|
|
// CHECK: call {{.*}} @"??$ReadField@US@@$07@@YAHAAUS@@@Z"
|
|
|
|
// CHECK: call {{.*}} @"??$ReadField@UM@@$0BA@@@YAHAAUM@@@Z"
|
|
|
|
// CHECK: call {{.*}} @"??$ReadField@UV@@$FM@A@@@YAHAAUV@@@Z"
|
|
|
|
// CHECK: call {{.*}} @"??$ReadField@UU@@$G7A@A@@@YAHAAUU@@@Z"
|
2014-02-06 01:27:08 +08:00
|
|
|
|
|
|
|
// MSVC mangles null member pointers in function templates wrong, but it gets
|
|
|
|
// them right in class templates.
|
2018-03-17 04:36:49 +08:00
|
|
|
// CHECK: call {{.*}} @"??$ReadField@US@@$0A@@@YAHAAUS@@@Z"
|
|
|
|
// CHECK: call {{.*}} @"??$ReadField@UM@@$0A@@@YAHAAUM@@@Z"
|
|
|
|
// CHECK: call {{.*}} @"??$ReadField@UV@@$0A@@@YAHAAUV@@@Z"
|
|
|
|
// CHECK: call {{.*}} @"??$ReadField@UU@@$0A@@@YAHAAUU@@@Z"
|
2014-02-06 01:27:08 +08:00
|
|
|
|
|
|
|
// Non-polymorphic null data memptr vs first field memptr. MSVC mangles these
|
|
|
|
// the same.
|
2018-03-17 04:36:49 +08:00
|
|
|
// CHECK: call {{.*}} @"??$ReadField@UA@@$0A@@@YAHAAUA@@@Z"
|
|
|
|
// CHECK: call {{.*}} @"??$ReadField@UA@@$0?0@@YAHAAUA@@@Z"
|
2014-02-06 01:27:08 +08:00
|
|
|
|
2014-02-07 03:14:16 +08:00
|
|
|
// Indirect fields are handled as-if they were simply members of their enclosing
|
|
|
|
// record.
|
2018-03-17 04:36:49 +08:00
|
|
|
// CHECK: call {{.*}} @"??$ReadField@UI@@$0A@@@YAHAAUI@@@Z"
|
|
|
|
// CHECK: call {{.*}} @"??$ReadField@UI@@$03@@YAHAAUI@@@Z"
|
2014-02-07 03:14:16 +08:00
|
|
|
|
2014-02-06 01:27:08 +08:00
|
|
|
// Test member function pointers.
|
|
|
|
template <typename T, void (T::*MFP)()>
|
|
|
|
void CallMethod(T &o) {
|
|
|
|
(o.*MFP)();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CallMethods() {
|
|
|
|
S s;
|
|
|
|
M m;
|
|
|
|
V v;
|
|
|
|
U u;
|
|
|
|
O o;
|
|
|
|
|
|
|
|
// Non-virtual methods.
|
|
|
|
CallMethod<S, &S::f>(s);
|
|
|
|
CallMethod<M, &M::f>(m);
|
|
|
|
CallMethod<V, &V::f>(v);
|
|
|
|
CallMethod<U, &U::f>(u);
|
|
|
|
|
|
|
|
// Virtual methods requiring thunk mangling.
|
|
|
|
CallMethod<S, &S::g>(s);
|
|
|
|
CallMethod<M, &M::g>(m);
|
|
|
|
CallMethod<V, &V::g>(v);
|
|
|
|
CallMethod<U, &U::g>(u);
|
|
|
|
|
|
|
|
// A member pointer for a non-primary vbase will have a non-zero this
|
|
|
|
// adjustment.
|
|
|
|
CallMethod<O, &O::g>(o);
|
|
|
|
|
|
|
|
// Null member pointers.
|
|
|
|
CallMethod<S, nullptr>(s);
|
|
|
|
CallMethod<M, nullptr>(m);
|
|
|
|
CallMethod<V, nullptr>(v);
|
|
|
|
CallMethod<U, nullptr>(u);
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: define {{.*}}CallMethods
|
2018-03-17 04:36:49 +08:00
|
|
|
// CHECK: call {{.*}} @"??$CallMethod@US@@$1?f@1@QAEXXZ@@YAXAAUS@@@Z"
|
|
|
|
// CHECK: call {{.*}} @"??$CallMethod@UM@@$H?f@1@QAEXXZA@@@YAXAAUM@@@Z"
|
|
|
|
// CHECK: call {{.*}} @"??$CallMethod@UV@@$I?f@1@QAEXXZA@A@@@YAXAAUV@@@Z"
|
|
|
|
// CHECK: call {{.*}} @"??$CallMethod@UU@@$J?f@1@QAEXXZA@A@A@@@YAXAAUU@@@Z"
|
2014-02-06 01:27:08 +08:00
|
|
|
|
|
|
|
// PR17034: MSVC reuses the same thunk for every virtual g method because they
|
|
|
|
// are all at vftable offset zero. They then mangle the name of the first thunk
|
|
|
|
// created into the name of the template instantiation, which is definitely a
|
|
|
|
// bug. We don't follow them here. Instead of ?_91@ backref below, they would
|
|
|
|
// get ?_9S@@ in every instantiation after the first.
|
|
|
|
|
2018-03-17 04:36:49 +08:00
|
|
|
// CHECK: call {{.*}} @"??$CallMethod@US@@$1??_91@$BA@AE@@YAXAAUS@@@Z"
|
|
|
|
// CHECK: call {{.*}} @"??$CallMethod@UM@@$H??_91@$BA@AEA@@@YAXAAUM@@@Z"
|
|
|
|
// CHECK: call {{.*}} @"??$CallMethod@UV@@$I??_91@$BA@AEA@A@@@YAXAAUV@@@Z"
|
|
|
|
// CHECK: call {{.*}} @"??$CallMethod@UU@@$J??_91@$BA@AEA@A@A@@@YAXAAUU@@@Z"
|
2014-02-06 01:27:08 +08:00
|
|
|
|
2018-03-17 04:36:49 +08:00
|
|
|
// CHECK: call {{.*}} @"??$CallMethod@UO@@$H??_91@$BA@AE3@@YAXAAUO@@@Z"
|
2014-02-06 01:27:08 +08:00
|
|
|
|
2018-03-17 04:36:49 +08:00
|
|
|
// CHECK: call {{.*}} @"??$CallMethod@US@@$0A@@@YAXAAUS@@@Z"
|
|
|
|
// CHECK: call {{.*}} @"??$CallMethod@UM@@$0A@@@YAXAAUM@@@Z"
|
|
|
|
// CHECK: call {{.*}} @"??$CallMethod@UV@@$0A@@@YAXAAUV@@@Z"
|
|
|
|
// CHECK: call {{.*}} @"??$CallMethod@UU@@$0A@@@YAXAAUU@@@Z"
|
2015-06-24 04:34:18 +08:00
|
|
|
|
|
|
|
namespace NegativeNVOffset {
|
|
|
|
struct A {};
|
|
|
|
struct B : virtual A {};
|
|
|
|
struct C : B {
|
|
|
|
virtual void f();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
template void CallMethod<NegativeNVOffset::C, &NegativeNVOffset::C::f>(NegativeNVOffset::C &);
|
|
|
|
|
2018-03-17 04:36:49 +08:00
|
|
|
// CHECK-LABEL: define {{.*}} @"??$CallMethod@UC@NegativeNVOffset@@$I??_912@$BA@AEPPPPPPPM@A@@@YAXAAUC@NegativeNVOffset@@@Z"
|