1 // RUN: %clang_cc1 -Wno-microsoft -fno-rtti -std=c++11 -emit-llvm %s -o - -triple=i386-pc-win32 | FileCheck %s
4 static_assert(sizeof(void (U::*)()) == 2 * sizeof(void*) + 2 * sizeof(int), "");
8 struct I
{ union { struct { int a
, b
; }; }; };
10 struct S
{ int a
, b
; void f(); virtual void g(); };
11 struct M
: A
, B
{ int a
, b
; void f(); virtual void g(); };
12 struct V
: virtual A
{ int a
, b
; void f(); virtual void g(); };
13 struct U
{ int a
, b
; void f(); virtual void g(); };
15 struct C
{ virtual void f(); };
16 struct D
{ virtual void g(); };
17 struct O
: C
, D
{ virtual void g(); }; // override of non-primary
19 // Test data member pointers.
20 template <typename T
, int T::*F
>
25 // Redeclare some of the classes so that the implicit attribute goes on the most
26 // recent redeclaration rather than the definition.
36 ReadField
<S
, &S::a
>(s
);
37 ReadField
<M
, &M::a
>(m
);
38 ReadField
<V
, &V::a
>(v
);
39 ReadField
<U
, &U::a
>(u
);
40 ReadField
<S
, &S::b
>(s
);
41 ReadField
<M
, &M::b
>(m
);
42 ReadField
<V
, &V::b
>(v
);
43 ReadField
<U
, &U::b
>(u
);
44 ReadField
<S
, nullptr>(s
);
45 ReadField
<M
, nullptr>(m
);
46 ReadField
<V
, nullptr>(v
);
47 ReadField
<U
, nullptr>(u
);
49 // Non-polymorphic null data memptr vs first field memptr.
50 ReadField
<A
, &A::a
>(a
);
51 ReadField
<A
, nullptr>(a
);
53 // Indirect fields injected from anonymous unions and structs
54 ReadField
<I
, &I::a
>(i
);
55 ReadField
<I
, &I::b
>(i
);
58 // CHECK-LABEL: define {{.*}}ReadFields
59 // CHECK: call {{.*}} @"??$ReadField@US@@$03@@YAHAAUS@@@Z"
60 // CHECK: call {{.*}} @"??$ReadField@UM@@$0M@@@YAHAAUM@@@Z"
61 // CHECK: call {{.*}} @"??$ReadField@UV@@$F7A@@@YAHAAUV@@@Z"
62 // CHECK: call {{.*}} @"??$ReadField@UU@@$G3A@A@@@YAHAAUU@@@Z"
63 // CHECK: call {{.*}} @"??$ReadField@US@@$07@@YAHAAUS@@@Z"
64 // CHECK: call {{.*}} @"??$ReadField@UM@@$0BA@@@YAHAAUM@@@Z"
65 // CHECK: call {{.*}} @"??$ReadField@UV@@$FM@A@@@YAHAAUV@@@Z"
66 // CHECK: call {{.*}} @"??$ReadField@UU@@$G7A@A@@@YAHAAUU@@@Z"
68 // MSVC mangles null member pointers in function templates wrong, but it gets
69 // them right in class templates.
70 // CHECK: call {{.*}} @"??$ReadField@US@@$0A@@@YAHAAUS@@@Z"
71 // CHECK: call {{.*}} @"??$ReadField@UM@@$0A@@@YAHAAUM@@@Z"
72 // CHECK: call {{.*}} @"??$ReadField@UV@@$0A@@@YAHAAUV@@@Z"
73 // CHECK: call {{.*}} @"??$ReadField@UU@@$0A@@@YAHAAUU@@@Z"
75 // Non-polymorphic null data memptr vs first field memptr. MSVC mangles these
77 // CHECK: call {{.*}} @"??$ReadField@UA@@$0A@@@YAHAAUA@@@Z"
78 // CHECK: call {{.*}} @"??$ReadField@UA@@$0?0@@YAHAAUA@@@Z"
80 // Indirect fields are handled as-if they were simply members of their enclosing
82 // CHECK: call {{.*}} @"??$ReadField@UI@@$0A@@@YAHAAUI@@@Z"
83 // CHECK: call {{.*}} @"??$ReadField@UI@@$03@@YAHAAUI@@@Z"
85 // Test member function pointers.
86 template <typename T
, void (T::*MFP
)()>
87 void CallMethod(T
&o
) {
98 // Non-virtual methods.
99 CallMethod
<S
, &S::f
>(s
);
100 CallMethod
<M
, &M::f
>(m
);
101 CallMethod
<V
, &V::f
>(v
);
102 CallMethod
<U
, &U::f
>(u
);
104 // Virtual methods requiring thunk mangling.
105 CallMethod
<S
, &S::g
>(s
);
106 CallMethod
<M
, &M::g
>(m
);
107 CallMethod
<V
, &V::g
>(v
);
108 CallMethod
<U
, &U::g
>(u
);
110 // A member pointer for a non-primary vbase will have a non-zero this
112 CallMethod
<O
, &O::g
>(o
);
114 // Null member pointers.
115 CallMethod
<S
, nullptr>(s
);
116 CallMethod
<M
, nullptr>(m
);
117 CallMethod
<V
, nullptr>(v
);
118 CallMethod
<U
, nullptr>(u
);
121 // CHECK-LABEL: define {{.*}}CallMethods
122 // CHECK: call {{.*}} @"??$CallMethod@US@@$1?f@1@QAEXXZ@@YAXAAUS@@@Z"
123 // CHECK: call {{.*}} @"??$CallMethod@UM@@$H?f@1@QAEXXZA@@@YAXAAUM@@@Z"
124 // CHECK: call {{.*}} @"??$CallMethod@UV@@$I?f@1@QAEXXZA@A@@@YAXAAUV@@@Z"
125 // CHECK: call {{.*}} @"??$CallMethod@UU@@$J?f@1@QAEXXZA@A@A@@@YAXAAUU@@@Z"
127 // PR17034: MSVC reuses the same thunk for every virtual g method because they
128 // are all at vftable offset zero. They then mangle the name of the first thunk
129 // created into the name of the template instantiation, which is definitely a
130 // bug. We don't follow them here. Instead of ?_91@ backref below, they would
131 // get ?_9S@@ in every instantiation after the first.
133 // CHECK: call {{.*}} @"??$CallMethod@US@@$1??_91@$BA@AE@@YAXAAUS@@@Z"
134 // CHECK: call {{.*}} @"??$CallMethod@UM@@$H??_91@$BA@AEA@@@YAXAAUM@@@Z"
135 // CHECK: call {{.*}} @"??$CallMethod@UV@@$I??_91@$BA@AEA@A@@@YAXAAUV@@@Z"
136 // CHECK: call {{.*}} @"??$CallMethod@UU@@$J??_91@$BA@AEA@A@A@@@YAXAAUU@@@Z"
138 // CHECK: call {{.*}} @"??$CallMethod@UO@@$H??_91@$BA@AE3@@YAXAAUO@@@Z"
140 // CHECK: call {{.*}} @"??$CallMethod@US@@$0A@@@YAXAAUS@@@Z"
141 // CHECK: call {{.*}} @"??$CallMethod@UM@@$0A@@@YAXAAUM@@@Z"
142 // CHECK: call {{.*}} @"??$CallMethod@UV@@$0A@@@YAXAAUV@@@Z"
143 // CHECK: call {{.*}} @"??$CallMethod@UU@@$0A@@@YAXAAUU@@@Z"
145 namespace NegativeNVOffset
{
147 struct B
: virtual A
{};
153 template void CallMethod
<NegativeNVOffset::C
, &NegativeNVOffset::C::f
>(NegativeNVOffset::C
&);
155 // CHECK-LABEL: define {{.*}} @"??$CallMethod@UC@NegativeNVOffset@@$I??_912@$BA@AEPPPPPPPM@A@@@YAXAAUC@NegativeNVOffset@@@Z"