Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGenCXX / microsoft-abi-member-pointers.cpp
blob2ac1961465d8a8a840ba1647c27df8bd8d5e2b16
1 // RUN: %clang_cc1 -std=c++11 -Wno-uninitialized -fno-rtti -emit-llvm %s -o - -triple=i386-pc-win32 -fms-extensions | FileCheck -allow-deprecated-dag-overlap %s
2 // RUN: %clang_cc1 -std=c++11 -Wno-uninitialized -fno-rtti -emit-llvm %s -o - -triple=x86_64-pc-win32 -fms-extensions | FileCheck %s -check-prefix=X64
3 // RUN: %clang_cc1 -std=c++17 -Wno-uninitialized -fno-rtti -emit-llvm %s -o - -triple=x86_64-pc-win32 -fms-extensions | FileCheck %s -check-prefix=X64
4 // RUN: %clang_cc1 -std=c++11 -Wno-uninitialized -fno-rtti -emit-llvm %s -o - -triple=i386-pc-win32 -DINCOMPLETE_VIRTUAL -fms-extensions -verify
5 // RUN: %clang_cc1 -std=c++11 -Wno-uninitialized -fno-rtti -emit-llvm %s -o - -triple=i386-pc-win32 -DINCOMPLETE_VIRTUAL -DMEMFUN -fms-extensions -verify
7 namespace pr37399 {
8 template <typename T>
9 struct Functor {
10 void (T::*PtrToMemberFunction)();
12 // CHECK-DAG: %"struct.pr37399::Functor" = type { ptr }
14 template <typename SomeType>
15 class SimpleDerivedFunctor;
16 template <typename SomeType>
17 class SimpleDerivedFunctor : public Functor<SimpleDerivedFunctor<SomeType>> {};
18 // CHECK-DAG: %"class.pr37399::SimpleDerivedFunctor" = type { %"struct.pr37399::Functor" }
20 SimpleDerivedFunctor<void> SimpleFunctor;
21 // CHECK-DAG: @"?SimpleFunctor@pr37399@@3V?$SimpleDerivedFunctor@X@1@A" = dso_local global %"class.pr37399::SimpleDerivedFunctor" zeroinitializer, align 4
23 short Global = 0;
24 template <typename SomeType>
25 class DerivedFunctor;
26 template <typename SomeType>
27 class DerivedFunctor
28 : public Functor<DerivedFunctor<void>> {
29 public:
30 void Foo() {
31 Global = 42;
35 class MultipleBase {
36 public:
37 MultipleBase() : Value() {}
38 short Value;
40 // CHECK-DAG: %"class.pr37399::MultipleBase" = type { i16 }
42 template <typename SomeType>
43 class MultiplyDerivedFunctor;
44 template <typename SomeType>
45 class MultiplyDerivedFunctor
46 : public Functor<MultiplyDerivedFunctor<void>>,
47 public MultipleBase {
48 public:
49 void Foo() {
50 MultipleBase::Value = 42*2;
54 class VirtualBase {
55 public:
56 VirtualBase() : Value() {}
57 short Value;
59 // CHECK-DAG: %"class.pr37399::VirtualBase" = type { i16 }
61 template <typename SomeType>
62 class VirtBaseFunctor
63 : public Functor<SomeType>,
64 public virtual VirtualBase{};
65 template <typename SomeType>
66 class VirtuallyDerivedFunctor;
67 template <typename SomeType>
68 class VirtuallyDerivedFunctor
69 : public VirtBaseFunctor<VirtuallyDerivedFunctor<void>>,
70 public virtual VirtualBase {
71 public:
72 void Foo() {
73 VirtualBase::Value = 42*3;
76 } // namespace pr37399
78 pr37399::DerivedFunctor<int> BFunctor;
79 // CHECK-DAG: @"?BFunctor@@3V?$DerivedFunctor@H@pr37399@@A" = dso_local global %"[[BFUNCTOR:class.pr37399::DerivedFunctor(\.[0-9]+)?]]" zeroinitializer, align 8
80 // CHECK-DAG: %"[[BFUNCTOR]]" = type { %"[[BFUNCTORBASE:struct.pr37399::Functor(\.[0-9]+)?]]" }
81 // CHECK-DAG: %"[[BFUNCTORBASE]]" = type { { ptr, i32, i32, i32 } }
82 pr37399::DerivedFunctor<void> AFunctor;
83 // CHECK-DAG: @"?AFunctor@@3V?$DerivedFunctor@X@pr37399@@A" = dso_local global %"[[AFUNCTOR:class.pr37399::DerivedFunctor(\.[0-9]+)?]]" zeroinitializer, align 8
84 // CHECK-DAG: %"[[AFUNCTOR]]" = type { %"[[AFUNCTORBASE:struct.pr37399::Functor(\.[0-9]+)?]]" }
85 // CHECK-DAG: %"[[AFUNCTORBASE]]" = type { { ptr, i32, i32, i32 } }
87 pr37399::MultiplyDerivedFunctor<int> DFunctor;
88 // CHECK-DAG: @"?DFunctor@@3V?$MultiplyDerivedFunctor@H@pr37399@@A" = dso_local global %"[[DFUNCTOR:class.pr37399::MultiplyDerivedFunctor(\.[0-9]+)?]]" zeroinitializer, align 8
89 // CHECK-DAG: %"[[DFUNCTOR]]" = type { %"[[DFUNCTORBASE:struct.pr37399::Functor(\.[0-9]+)?]]", %"class.pr37399::MultipleBase", [6 x i8] }
90 // CHECK-DAG: %"[[DFUNCTORBASE]]" = type { { ptr, i32, i32, i32 } }
91 pr37399::MultiplyDerivedFunctor<void> CFunctor;
92 // CHECK-DAG: @"?CFunctor@@3V?$MultiplyDerivedFunctor@X@pr37399@@A" = dso_local global %"[[CFUNCTOR:class.pr37399::MultiplyDerivedFunctor(\.[0-9]+)?]]" zeroinitializer, align 8
93 // CHECK-DAG: %"[[CFUNCTOR]]" = type { %"[[CFUNCTORBASE:struct.pr37399::Functor(\.[0-9]+)?]]", %"class.pr37399::MultipleBase", [6 x i8] }
94 // CHECK-DAG: %"[[CFUNCTORBASE]]" = type { { ptr, i32, i32, i32 } }
96 pr37399::VirtuallyDerivedFunctor<int> FFunctor;
97 // CHECK-DAG: @"?FFunctor@@3V?$VirtuallyDerivedFunctor@H@pr37399@@A" = dso_local global %"[[FFUNCTOR:class.pr37399::VirtuallyDerivedFunctor(\.[0-9]+)?]]" zeroinitializer, align 8
98 // CHECK-DAG: %"[[FFUNCTOR]]" = type { %"class.pr37399::VirtBaseFunctor.base", %"class.pr37399::VirtualBase" }
99 pr37399::VirtuallyDerivedFunctor<void> EFunctor;
100 // CHECK-DAG: @"?EFunctor@@3V?$VirtuallyDerivedFunctor@X@pr37399@@A" = dso_local global %"[[EFUNCTOR:class.pr37399::VirtuallyDerivedFunctor(\.[0-9]+)?]]" zeroinitializer, align 8
101 // CHECK-DAG: %"[[EFUNCTOR]]" = type { %"class.pr37399::VirtBaseFunctor.base", %"class.pr37399::VirtualBase" }
103 // CHECK-DAG: %"class.pr37399::VirtBaseFunctor.base" = type <{ %"[[VFUNCTORBASE:struct.pr37399::Functor(\.[0-9]+)?]]", ptr, [4 x i8] }>
104 // CHECK-DAG: %"[[VFUNCTORBASE]]" = type { { ptr, i32, i32, i32 } }
106 namespace pr37399 {
107 void SingleInheritanceFnPtrCall() {
108 BFunctor.PtrToMemberFunction = &DerivedFunctor<void>::Foo;
109 (AFunctor.*(BFunctor.PtrToMemberFunction))();
111 void MultipleInheritanceFnPtrCall() {
112 DFunctor.PtrToMemberFunction = &MultiplyDerivedFunctor<void>::Foo;
113 Global = CFunctor.MultipleBase::Value;
114 (CFunctor.*(DFunctor.PtrToMemberFunction))();
115 Global = CFunctor.MultipleBase::Value;
117 void VirtualInheritanceFnPtrCall() {
118 FFunctor.PtrToMemberFunction = &VirtuallyDerivedFunctor<void>::Foo;
119 Global = EFunctor.VirtualBase::Value;
120 (EFunctor.*(FFunctor.PtrToMemberFunction))();
121 Global = EFunctor.VirtualBase::Value;
123 } // namespace pr37399
125 namespace pr43803 {
126 // This case is interesting because it exercises conversion between member
127 // pointer types when emitting constants.
129 struct B;
130 struct C { int B::*option; };
131 extern const C table[3];
132 struct A {
133 int x, y;
134 // Test the indirect case.
135 struct {
136 int z;
139 struct B : A {};
140 const C table[] = {
141 {&B::x},
142 {&B::y},
143 {&B::z},
146 // CHECK: @"?table@pr43803@@3QBUC@1@B" = dso_local constant [3 x %"struct.pr43803::C"]
147 // CHECK-SAME: [%"struct.pr43803::C" { { i32, i32, i32 } zeroinitializer, [4 x i8] undef },
148 // CHECK-SAME: %"struct.pr43803::C" { { i32, i32, i32 } { i32 4, i32 0, i32 0 }, [4 x i8] undef },
149 // CHECK-SAME: %"struct.pr43803::C" { { i32, i32, i32 } { i32 8, i32 0, i32 0 }, [4 x i8] undef }]
152 namespace pr48687 {
153 template <typename T> struct A {
154 T value;
155 static constexpr auto address = &A<T>::value;
157 extern template class A<float>;
158 template class A<float>;
159 // CHECK: @"?address@?$A@M@pr48687@@2QQ12@MQ12@" = weak_odr dso_local constant i32 0, comdat, align 4
162 struct PR26313_Y;
163 typedef void (PR26313_Y::*PR26313_FUNC)();
164 struct PR26313_X {
165 PR26313_FUNC *ptr;
166 PR26313_X();
168 PR26313_X::PR26313_X() {}
169 void PR26313_f(PR26313_FUNC *p) { delete p; }
171 struct PR26313_Z;
172 int PR26313_Z::**a = nullptr;
173 int PR26313_Z::*b = *a;
174 // CHECK-DAG: @"?a@@3PAPQPR26313_Z@@HA" = dso_local global ptr null, align 4
175 // CHECK-DAG: @"?b@@3PQPR26313_Z@@HQ1@" = dso_local global { i32, i32, i32 } { i32 0, i32 0, i32 -1 }, align 4
177 namespace PR20947 {
178 struct A;
179 int A::**a = nullptr;
180 // CHECK-DAG: @"?a@PR20947@@3PAPQA@1@HA" = dso_local global ptr null, align 4
182 struct B;
183 int B::*&b = b;
184 // CHECK-DAG: @"?b@PR20947@@3AAPQB@1@HA" = dso_local global ptr null, align 4
187 namespace PR20017 {
188 template <typename T>
189 struct A {
190 int T::*m_fn1() { return nullptr; }
192 struct B;
193 auto a = &A<B>::m_fn1;
194 // CHECK-DAG: @"?a@PR20017@@3P8?$A@UB@PR20017@@@1@AEPQB@1@HXZQ21@" = dso_local global ptr @"?m_fn1@?$A@UB@PR20017@@@PR20017@@QAEPQB@2@HXZ", align 4
197 #ifndef INCOMPLETE_VIRTUAL
198 struct B1 {
199 void foo();
200 int b;
202 struct B2 {
203 int b2;
204 void foo();
206 struct Single : B1 {
207 void foo();
209 struct Multiple : B1, B2 {
210 int m;
211 void foo();
213 struct Virtual : virtual B1 {
214 int v;
215 void foo();
218 struct POD {
219 int a;
220 int b;
223 struct Polymorphic {
224 virtual void myVirtual();
225 int a;
226 int b;
229 // This class uses the virtual inheritance model, yet its vbptr offset is not 0.
230 // We still use zero for the null field offset, despite it being a valid field
231 // offset.
232 struct NonZeroVBPtr : POD, Virtual {
233 int n;
234 void foo();
237 struct Unspecified;
238 struct UnspecSingle;
240 // Check that we can lower the LLVM types and get the null initializers right.
241 int Single ::*s_d_memptr;
242 int Polymorphic::*p_d_memptr;
243 int Multiple ::*m_d_memptr;
244 int Virtual ::*v_d_memptr;
245 int NonZeroVBPtr::*n_d_memptr;
246 int Unspecified::*u_d_memptr;
247 int UnspecSingle::*us_d_memptr;
248 // CHECK: @"?s_d_memptr@@3PQSingle@@HQ1@" = dso_local global i32 -1, align 4
249 // CHECK: @"?p_d_memptr@@3PQPolymorphic@@HQ1@" = dso_local global i32 0, align 4
250 // CHECK: @"?m_d_memptr@@3PQMultiple@@HQ1@" = dso_local global i32 -1, align 4
251 // CHECK: @"?v_d_memptr@@3PQVirtual@@HQ1@" = dso_local global { i32, i32 }
252 // CHECK: { i32 0, i32 -1 }, align 4
253 // CHECK: @"?n_d_memptr@@3PQNonZeroVBPtr@@HQ1@" = dso_local global { i32, i32 }
254 // CHECK: { i32 0, i32 -1 }, align 4
255 // CHECK: @"?u_d_memptr@@3PQUnspecified@@HQ1@" = dso_local global { i32, i32, i32 }
256 // CHECK: { i32 0, i32 0, i32 -1 }, align 4
257 // CHECK: @"?us_d_memptr@@3PQUnspecSingle@@HQ1@" = dso_local global { i32, i32, i32 }
258 // CHECK: { i32 0, i32 0, i32 -1 }, align 4
260 void (Single ::*s_f_memptr)();
261 void (Multiple::*m_f_memptr)();
262 void (Virtual ::*v_f_memptr)();
263 // CHECK: @"?s_f_memptr@@3P8Single@@AEXXZQ1@" = dso_local global ptr null, align 4
264 // CHECK: @"?m_f_memptr@@3P8Multiple@@AEXXZQ1@" = dso_local global { ptr, i32 } zeroinitializer, align 4
265 // CHECK: @"?v_f_memptr@@3P8Virtual@@AEXXZQ1@" = dso_local global { ptr, i32, i32 } zeroinitializer, align 4
267 // We can define Unspecified after locking in the inheritance model.
268 struct Unspecified : Multiple, Virtual {
269 void foo();
270 int u;
273 struct UnspecSingle {
274 void foo();
277 // Test memptr emission in a constant expression.
278 namespace Const {
279 void (Single ::*s_f_mp)() = &Single::foo;
280 void (Multiple ::*m_f_mp)() = &B2::foo;
281 void (Virtual ::*v_f_mp)() = &Virtual::foo;
282 void (Unspecified::*u_f_mp)() = &Unspecified::foo;
283 void (UnspecSingle::*us_f_mp)() = &UnspecSingle::foo;
284 // CHECK: @"?s_f_mp@Const@@3P8Single@@AEXXZQ2@" =
285 // CHECK: global ptr @"?foo@Single@@QAEXXZ", align 4
286 // CHECK: @"?m_f_mp@Const@@3P8Multiple@@AEXXZQ2@" =
287 // CHECK: global { ptr, i32 } { ptr @"?foo@B2@@QAEXXZ", i32 4 }, align 4
288 // CHECK: @"?v_f_mp@Const@@3P8Virtual@@AEXXZQ2@" =
289 // CHECK: global { ptr, i32, i32 } { ptr @"?foo@Virtual@@QAEXXZ", i32 0, i32 0 }, align 4
290 // CHECK: @"?u_f_mp@Const@@3P8Unspecified@@AEXXZQ2@" =
291 // CHECK: global { ptr, i32, i32, i32 } { ptr @"?foo@Unspecified@@QAEXXZ", i32 0, i32 0, i32 0 }, align 4
292 // CHECK: @"?us_f_mp@Const@@3P8UnspecSingle@@AEXXZQ2@" =
293 // CHECK: global { ptr, i32, i32, i32 } { ptr @"?foo@UnspecSingle@@QAEXXZ", i32 0, i32 0, i32 0 }, align 4
296 namespace CastParam {
297 // This exercises ConstExprEmitter instead of ValueDecl::evaluateValue. The
298 // extra reinterpret_cast for the parameter type requires more careful folding.
299 // FIXME: Or does it? If reinterpret_casts are no-ops, we should be able to
300 // strip them in evaluateValue() and just proceed as normal with an APValue.
301 struct A {
302 int a;
303 void foo(A *p);
305 struct B { int b; };
306 struct C : B, A { int c; };
308 void (A::*ptr1)(void *) = (void (A::*)(void *)) &A::foo;
309 // CHECK: @"?ptr1@CastParam@@3P8A@1@AEXPAX@ZQ21@" =
310 // CHECK: global ptr @"?foo@A@CastParam@@QAEXPAU12@@Z", align 4
312 // Try a reinterpret_cast followed by a memptr conversion.
313 void (C::*ptr2)(void *) = (void (C::*)(void *)) (void (A::*)(void *)) &A::foo;
314 // CHECK: @"?ptr2@CastParam@@3P8C@1@AEXPAX@ZQ21@" =
315 // CHECK: global { ptr, i32 } { ptr @"?foo@A@CastParam@@QAEXPAU12@@Z", i32 4 }, align 4
317 void (C::*ptr3)(void *) = (void (C::*)(void *)) (void (A::*)(void *)) (void (A::*)(A *)) 0;
318 // CHECK: @"?ptr3@CastParam@@3P8C@1@AEXPAX@ZQ21@" =
319 // CHECK: global { ptr, i32 } zeroinitializer, align 4
321 struct D : C {
322 virtual void isPolymorphic();
323 int d;
326 // Try a cast that changes the inheritance model. Null for D is 0, but null for
327 // C is -1. We need the cast to long in order to hit the non-APValue path.
328 int C::*ptr4 = (int C::*) (int D::*) (long D::*) 0;
329 // CHECK: @"?ptr4@CastParam@@3PQC@1@HQ21@" = dso_local global i32 -1, align 4
331 // MSVC rejects this but we accept it.
332 int C::*ptr5 = (int C::*) (long D::*) 0;
333 // CHECK: @"?ptr5@CastParam@@3PQC@1@HQ21@" = dso_local global i32 -1, align 4
336 struct UnspecWithVBPtr;
337 int UnspecWithVBPtr::*forceUnspecWithVBPtr;
338 struct UnspecWithVBPtr : B1, virtual B2 {
339 int u;
340 void foo();
343 // Test emitting non-virtual member pointers in a non-constexpr setting.
344 void EmitNonVirtualMemberPointers() {
345 void (Single ::*s_f_memptr)() = &Single::foo;
346 void (Multiple ::*m_f_memptr)() = &Multiple::foo;
347 void (Virtual ::*v_f_memptr)() = &Virtual::foo;
348 void (Unspecified::*u_f_memptr)() = &Unspecified::foo;
349 void (UnspecWithVBPtr::*u2_f_memptr)() = &UnspecWithVBPtr::foo;
350 // CHECK: define dso_local void @"?EmitNonVirtualMemberPointers@@YAXXZ"() {{.*}} {
351 // CHECK: alloca ptr, align 4
352 // CHECK: alloca { ptr, i32 }, align 4
353 // CHECK: alloca { ptr, i32, i32 }, align 4
354 // CHECK: alloca { ptr, i32, i32, i32 }, align 4
355 // CHECK: store ptr @"?foo@Single@@QAEXXZ", ptr %{{.*}}, align 4
356 // CHECK: store { ptr, i32 }
357 // CHECK: { ptr @"?foo@Multiple@@QAEXXZ", i32 0 },
358 // CHECK: ptr %{{.*}}, align 4
359 // CHECK: store { ptr, i32, i32 }
360 // CHECK: { ptr @"?foo@Virtual@@QAEXXZ", i32 0, i32 0 },
361 // CHECK: ptr %{{.*}}, align 4
362 // CHECK: store { ptr, i32, i32, i32 }
363 // CHECK: { ptr @"?foo@Unspecified@@QAEXXZ", i32 0, i32 0, i32 0 },
364 // CHECK: ptr %{{.*}}, align 4
365 // CHECK: store { ptr, i32, i32, i32 }
366 // CHECK: { ptr @"?foo@UnspecWithVBPtr@@QAEXXZ",
367 // CHECK: i32 0, i32 0, i32 0 },
368 // CHECK: ptr %{{.*}}, align 4
369 // CHECK: ret void
370 // CHECK: }
373 void podMemPtrs() {
374 int POD::*memptr;
375 memptr = &POD::a;
376 memptr = &POD::b;
377 if (memptr)
378 memptr = 0;
379 // Check that member pointers use the right offsets and that null is -1.
380 // CHECK: define dso_local void @"?podMemPtrs@@YAXXZ"() {{.*}} {
381 // CHECK: %[[memptr:.*]] = alloca i32, align 4
382 // CHECK-NEXT: store i32 0, ptr %[[memptr]], align 4
383 // CHECK-NEXT: store i32 4, ptr %[[memptr]], align 4
384 // CHECK-NEXT: %[[memptr_val:.*]] = load i32, ptr %[[memptr]], align 4
385 // CHECK-NEXT: %{{.*}} = icmp ne i32 %[[memptr_val]], -1
386 // CHECK-NEXT: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}
387 // CHECK: store i32 -1, ptr %[[memptr]], align 4
388 // CHECK: ret void
389 // CHECK: }
392 void polymorphicMemPtrs() {
393 int Polymorphic::*memptr;
394 memptr = &Polymorphic::a;
395 memptr = &Polymorphic::b;
396 if (memptr)
397 memptr = 0;
398 // Member pointers for polymorphic classes include the vtable slot in their
399 // offset and use 0 to represent null.
400 // CHECK: define dso_local void @"?polymorphicMemPtrs@@YAXXZ"() {{.*}} {
401 // CHECK: %[[memptr:.*]] = alloca i32, align 4
402 // CHECK-NEXT: store i32 4, ptr %[[memptr]], align 4
403 // CHECK-NEXT: store i32 8, ptr %[[memptr]], align 4
404 // CHECK-NEXT: %[[memptr_val:.*]] = load i32, ptr %[[memptr]], align 4
405 // CHECK-NEXT: %{{.*}} = icmp ne i32 %[[memptr_val]], 0
406 // CHECK-NEXT: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}
407 // CHECK: store i32 0, ptr %[[memptr]], align 4
408 // CHECK: ret void
409 // CHECK: }
412 bool nullTestDataUnspecified(int Unspecified::*mp) {
413 return mp;
414 // CHECK: define dso_local noundef zeroext i1 @"?nullTestDataUnspecified@@YA_NPQUnspecified@@H@Z"{{.*}} {
415 // CHECK: %{{.*}} = load { i32, i32, i32 }, ptr %{{.*}}, align 4
416 // CHECK: store { i32, i32, i32 } {{.*}} align 4
417 // CHECK: %[[mp:.*]] = load { i32, i32, i32 }, ptr %{{.*}}, align 4
418 // CHECK: %[[mp0:.*]] = extractvalue { i32, i32, i32 } %[[mp]], 0
419 // CHECK: %[[cmp0:.*]] = icmp ne i32 %[[mp0]], 0
420 // CHECK: %[[mp1:.*]] = extractvalue { i32, i32, i32 } %[[mp]], 1
421 // CHECK: %[[cmp1:.*]] = icmp ne i32 %[[mp1]], 0
422 // CHECK: %[[and0:.*]] = or i1 %[[cmp0]], %[[cmp1]]
423 // CHECK: %[[mp2:.*]] = extractvalue { i32, i32, i32 } %[[mp]], 2
424 // CHECK: %[[cmp2:.*]] = icmp ne i32 %[[mp2]], -1
425 // CHECK: %[[and1:.*]] = or i1 %[[and0]], %[[cmp2]]
426 // CHECK: ret i1 %[[and1]]
427 // CHECK: }
429 // Pass this large type indirectly.
430 // X64-LABEL: define dso_local noundef zeroext i1 @"?nullTestDataUnspecified@@
431 // X64: (ptr noundef %0)
434 bool nullTestFunctionUnspecified(void (Unspecified::*mp)()) {
435 return mp;
436 // CHECK: define dso_local noundef zeroext i1 @"?nullTestFunctionUnspecified@@YA_NP8Unspecified@@AEXXZ@Z"{{.*}} {
437 // CHECK: %{{.*}} = load { ptr, i32, i32, i32 }, ptr %{{.*}}, align 4
438 // CHECK: store { ptr, i32, i32, i32 } {{.*}} align 4
439 // CHECK: %[[mp:.*]] = load { ptr, i32, i32, i32 }, ptr %{{.*}}, align 4
440 // CHECK: %[[mp0:.*]] = extractvalue { ptr, i32, i32, i32 } %[[mp]], 0
441 // CHECK: %[[cmp0:.*]] = icmp ne ptr %[[mp0]], null
442 // CHECK: ret i1 %[[cmp0]]
443 // CHECK: }
446 int loadDataMemberPointerVirtual(Virtual *o, int Virtual::*memptr) {
447 return o->*memptr;
448 // Test that we can unpack this aggregate member pointer and load the member
449 // data pointer.
450 // CHECK: define dso_local noundef i32 @"?loadDataMemberPointerVirtual@@YAHPAUVirtual@@PQ1@H@Z"{{.*}} {
451 // CHECK: %[[o:.*]] = load ptr, ptr %{{.*}}, align 4
452 // CHECK: %[[memptr:.*]] = load { i32, i32 }, ptr %{{.*}}, align 4
453 // CHECK: %[[memptr0:.*]] = extractvalue { i32, i32 } %[[memptr:.*]], 0
454 // CHECK: %[[memptr1:.*]] = extractvalue { i32, i32 } %[[memptr:.*]], 1
455 // CHECK: %[[vbptr:.*]] = getelementptr inbounds i8, ptr %[[o]], i32 0
456 // CHECK: %[[vbtable:.*]] = load ptr, ptr %[[vbptr_a:.*]]
457 // CHECK: %[[memptr1_shr:.*]] = ashr exact i32 %[[memptr1]], 2
458 // CHECK: %[[v7:.*]] = getelementptr inbounds i32, ptr %[[vbtable]], i32 %[[memptr1_shr]]
459 // CHECK: %[[vbase_offs:.*]] = load i32, ptr %[[v7]]
460 // CHECK: %[[v10:.*]] = getelementptr inbounds i8, ptr %[[vbptr]], i32 %[[vbase_offs]]
461 // CHECK: %[[offset:.*]] = getelementptr inbounds i8, ptr %[[v10]], i32 %[[memptr0]]
462 // CHECK: %[[v12:.*]] = load i32, ptr %[[offset]]
463 // CHECK: ret i32 %[[v12]]
464 // CHECK: }
466 // A two-field data memptr on x64 gets coerced to i64 and is passed in a
467 // register or memory.
468 // X64-LABEL: define dso_local noundef i32 @"?loadDataMemberPointerVirtual@@YAHPEAUVirtual@@PEQ1@H@Z"
469 // X64: (ptr noundef %o, i64 %memptr.coerce)
472 int loadDataMemberPointerUnspecified(Unspecified *o, int Unspecified::*memptr) {
473 return o->*memptr;
474 // Test that we can unpack this aggregate member pointer and load the member
475 // data pointer.
476 // CHECK: define dso_local noundef i32 @"?loadDataMemberPointerUnspecified@@YAHPAUUnspecified@@PQ1@H@Z"{{.*}} {
477 // CHECK: %[[o:.*]] = load ptr, ptr %{{.*}}, align 4
478 // CHECK: %[[memptr:.*]] = load { i32, i32, i32 }, ptr %{{.*}}, align 4
479 // CHECK: %[[memptr0:.*]] = extractvalue { i32, i32, i32 } %[[memptr:.*]], 0
480 // CHECK: %[[memptr1:.*]] = extractvalue { i32, i32, i32 } %[[memptr:.*]], 1
481 // CHECK: %[[memptr2:.*]] = extractvalue { i32, i32, i32 } %[[memptr:.*]], 2
482 // CHECK: %[[is_vbase:.*]] = icmp ne i32 %[[memptr2]], 0
483 // CHECK: br i1 %[[is_vbase]], label %[[vadjust:.*]], label %[[skip:.*]]
485 // CHECK: [[vadjust]]
486 // CHECK: %[[vbptr:.*]] = getelementptr inbounds i8, ptr %[[o]], i32 %[[memptr1]]
487 // CHECK: %[[vbtable:.*]] = load ptr, ptr %[[vbptr_a:.*]]
488 // CHECK: %[[memptr2_shr:.*]] = ashr exact i32 %[[memptr2]], 2
489 // CHECK: %[[v7:.*]] = getelementptr inbounds i32, ptr %[[vbtable]], i32 %[[memptr2_shr]]
490 // CHECK: %[[vbase_offs:.*]] = load i32, ptr %[[v7]]
491 // CHECK: %[[base_adj:.*]] = getelementptr inbounds i8, ptr %[[vbptr]], i32 %[[vbase_offs]]
493 // CHECK: [[skip]]
494 // CHECK: %[[new_base:.*]] = phi ptr [ %[[o]], %{{.*}} ], [ %[[base_adj]], %[[vadjust]] ]
495 // CHECK: %[[offset:.*]] = getelementptr inbounds i8, ptr %[[new_base]], i32 %[[memptr0]]
496 // CHECK: %[[v12:.*]] = load i32, ptr %[[offset]]
497 // CHECK: ret i32 %[[v12]]
498 // CHECK: }
501 void callMemberPointerSingle(Single *o, void (Single::*memptr)()) {
502 (o->*memptr)();
503 // Just look for an indirect thiscall.
504 // CHECK: define dso_local void @"?callMemberPointerSingle@@{{.*}} {{.*}} {
505 // CHECK: call x86_thiscallcc void %{{.*}}({{.*}} %{{.*}})
506 // CHECK: ret void
507 // CHECK: }
509 // X64-LABEL: define dso_local void @"?callMemberPointerSingle@@
510 // X64: (ptr noundef %o, ptr %memptr)
511 // X64: ret void
514 void callMemberPointerMultiple(Multiple *o, void (Multiple::*memptr)()) {
515 (o->*memptr)();
516 // CHECK: define dso_local void @"?callMemberPointerMultiple@@{{.*}} {
517 // CHECK: %[[memptr0:.*]] = extractvalue { ptr, i32 } %{{.*}}, 0
518 // CHECK: %[[memptr1:.*]] = extractvalue { ptr, i32 } %{{.*}}, 1
519 // CHECK: %[[this_adjusted:.*]] = getelementptr inbounds i8, ptr %{{.*}}, i32 %[[memptr1]]
520 // CHECK: call x86_thiscallcc void %[[memptr0]]({{.*}} %[[this_adjusted]])
521 // CHECK: ret void
522 // CHECK: }
525 void callMemberPointerVirtualBase(Virtual *o, void (Virtual::*memptr)()) {
526 (o->*memptr)();
527 // This shares a lot with virtual data member pointers.
528 // CHECK: define dso_local void @"?callMemberPointerVirtualBase@@{{.*}} {
529 // CHECK: %[[memptr0:.*]] = extractvalue { ptr, i32, i32 } %{{.*}}, 0
530 // CHECK: %[[memptr1:.*]] = extractvalue { ptr, i32, i32 } %{{.*}}, 1
531 // CHECK: %[[memptr2:.*]] = extractvalue { ptr, i32, i32 } %{{.*}}, 2
532 // CHECK: %[[vbptr:.*]] = getelementptr inbounds i8, ptr %{{.*}}, i32 0
533 // CHECK: %[[vbtable:.*]] = load ptr, ptr %[[vbptr_a:.*]]
534 // CHECK: %[[memptr2_shr:.*]] = ashr exact i32 %[[memptr2]], 2
535 // CHECK: %[[v7:.*]] = getelementptr inbounds i32, ptr %[[vbtable]], i32 %[[memptr2_shr]]
536 // CHECK: %[[vbase_offs:.*]] = load i32, ptr %[[v7]]
537 // CHECK: %[[v10:.*]] = getelementptr inbounds i8, ptr %[[vbptr]], i32 %[[vbase_offs]]
538 // CHECK: %[[this_adjusted:.*]] = getelementptr inbounds i8, ptr %[[v10]], i32 %[[memptr1]]
539 // CHECK: call x86_thiscallcc void %[[memptr0]]({{.*}} %[[this_adjusted]])
540 // CHECK: ret void
541 // CHECK: }
544 bool compareSingleFunctionMemptr(void (Single::*l)(), void (Single::*r)()) {
545 return l == r;
546 // Should only be one comparison here.
547 // CHECK: define dso_local noundef zeroext i1 @"?compareSingleFunctionMemptr@@YA_NP8Single@@AEXXZ0@Z"{{.*}} {
548 // CHECK-NOT: icmp
549 // CHECK: %[[r:.*]] = icmp eq
550 // CHECK-NOT: icmp
551 // CHECK: ret i1 %[[r]]
552 // CHECK: }
554 // X64-LABEL: define dso_local noundef zeroext i1 @"?compareSingleFunctionMemptr@@
555 // X64: (ptr %{{[^,]*}}, ptr %{{[^)]*}})
558 bool compareNeqSingleFunctionMemptr(void (Single::*l)(), void (Single::*r)()) {
559 return l != r;
560 // Should only be one comparison here.
561 // CHECK: define dso_local noundef zeroext i1 @"?compareNeqSingleFunctionMemptr@@YA_NP8Single@@AEXXZ0@Z"{{.*}} {
562 // CHECK-NOT: icmp
563 // CHECK: %[[r:.*]] = icmp ne
564 // CHECK-NOT: icmp
565 // CHECK: ret i1 %[[r]]
566 // CHECK: }
569 bool unspecFuncMemptrEq(void (Unspecified::*l)(), void (Unspecified::*r)()) {
570 return l == r;
571 // CHECK: define dso_local noundef zeroext i1 @"?unspecFuncMemptrEq@@YA_NP8Unspecified@@AEXXZ0@Z"{{.*}} {
572 // CHECK: %[[lhs0:.*]] = extractvalue { ptr, i32, i32, i32 } %[[l:.*]], 0
573 // CHECK: %{{.*}} = extractvalue { ptr, i32, i32, i32 } %[[r:.*]], 0
574 // CHECK: %[[cmp0:.*]] = icmp eq ptr %[[lhs0]], %{{.*}}
575 // CHECK: %{{.*}} = extractvalue { ptr, i32, i32, i32 } %[[l]], 1
576 // CHECK: %{{.*}} = extractvalue { ptr, i32, i32, i32 } %[[r]], 1
577 // CHECK: %[[cmp1:.*]] = icmp eq i32
578 // CHECK: %{{.*}} = extractvalue { ptr, i32, i32, i32 } %[[l]], 2
579 // CHECK: %{{.*}} = extractvalue { ptr, i32, i32, i32 } %[[r]], 2
580 // CHECK: %[[cmp2:.*]] = icmp eq i32
581 // CHECK: %[[res12:.*]] = and i1 %[[cmp1]], %[[cmp2]]
582 // CHECK: %{{.*}} = extractvalue { ptr, i32, i32, i32 } %[[l]], 3
583 // CHECK: %{{.*}} = extractvalue { ptr, i32, i32, i32 } %[[r]], 3
584 // CHECK: %[[cmp3:.*]] = icmp eq i32
585 // CHECK: %[[res123:.*]] = and i1 %[[res12]], %[[cmp3]]
586 // CHECK: %[[iszero:.*]] = icmp eq ptr %[[lhs0]], null
587 // CHECK: %[[bits_or_null:.*]] = or i1 %[[res123]], %[[iszero]]
588 // CHECK: %{{.*}} = and i1 %[[bits_or_null]], %[[cmp0]]
589 // CHECK: ret i1 %{{.*}}
590 // CHECK: }
592 // X64-LABEL: define dso_local noundef zeroext i1 @"?unspecFuncMemptrEq@@
593 // X64: (ptr noundef %0, ptr noundef %1)
596 bool unspecFuncMemptrNeq(void (Unspecified::*l)(), void (Unspecified::*r)()) {
597 return l != r;
598 // CHECK: define dso_local noundef zeroext i1 @"?unspecFuncMemptrNeq@@YA_NP8Unspecified@@AEXXZ0@Z"{{.*}} {
599 // CHECK: %[[lhs0:.*]] = extractvalue { ptr, i32, i32, i32 } %[[l:.*]], 0
600 // CHECK: %{{.*}} = extractvalue { ptr, i32, i32, i32 } %[[r:.*]], 0
601 // CHECK: %[[cmp0:.*]] = icmp ne ptr %[[lhs0]], %{{.*}}
602 // CHECK: %{{.*}} = extractvalue { ptr, i32, i32, i32 } %[[l]], 1
603 // CHECK: %{{.*}} = extractvalue { ptr, i32, i32, i32 } %[[r]], 1
604 // CHECK: %[[cmp1:.*]] = icmp ne i32
605 // CHECK: %{{.*}} = extractvalue { ptr, i32, i32, i32 } %[[l]], 2
606 // CHECK: %{{.*}} = extractvalue { ptr, i32, i32, i32 } %[[r]], 2
607 // CHECK: %[[cmp2:.*]] = icmp ne i32
608 // CHECK: %[[res12:.*]] = or i1 %[[cmp1]], %[[cmp2]]
609 // CHECK: %{{.*}} = extractvalue { ptr, i32, i32, i32 } %[[l]], 3
610 // CHECK: %{{.*}} = extractvalue { ptr, i32, i32, i32 } %[[r]], 3
611 // CHECK: %[[cmp3:.*]] = icmp ne i32
612 // CHECK: %[[res123:.*]] = or i1 %[[res12]], %[[cmp3]]
613 // CHECK: %[[iszero:.*]] = icmp ne ptr %[[lhs0]], null
614 // CHECK: %[[bits_or_null:.*]] = and i1 %[[res123]], %[[iszero]]
615 // CHECK: %{{.*}} = or i1 %[[bits_or_null]], %[[cmp0]]
616 // CHECK: ret i1 %{{.*}}
617 // CHECK: }
620 bool unspecDataMemptrEq(int Unspecified::*l, int Unspecified::*r) {
621 return l == r;
622 // CHECK: define dso_local noundef zeroext i1 @"?unspecDataMemptrEq@@YA_NPQUnspecified@@H0@Z"{{.*}} {
623 // CHECK: extractvalue { i32, i32, i32 } %{{.*}}, 0
624 // CHECK: extractvalue { i32, i32, i32 } %{{.*}}, 0
625 // CHECK: icmp eq i32
626 // CHECK: extractvalue { i32, i32, i32 } %{{.*}}, 1
627 // CHECK: extractvalue { i32, i32, i32 } %{{.*}}, 1
628 // CHECK: icmp eq i32
629 // CHECK: extractvalue { i32, i32, i32 } %{{.*}}, 2
630 // CHECK: extractvalue { i32, i32, i32 } %{{.*}}, 2
631 // CHECK: icmp eq i32
632 // CHECK: and i1
633 // CHECK: and i1
634 // CHECK: ret i1
635 // CHECK: }
637 // X64-LABEL: define dso_local noundef zeroext i1 @"?unspecDataMemptrEq@@
638 // X64: (ptr noundef %0, ptr noundef %1)
641 void (Multiple::*convertB2FuncToMultiple(void (B2::*mp)()))() {
642 return mp;
643 // CHECK: define dso_local i64 @"?convertB2FuncToMultiple@@YAP8Multiple@@AEXXZP8B2@@AEXXZ@Z"{{.*}} {
644 // CHECK: store
645 // CHECK: %[[mp:.*]] = load ptr, ptr %{{.*}}, align 4
646 // CHECK: icmp ne ptr %[[mp]], null
647 // CHECK: br i1 %{{.*}} label %{{.*}}, label %{{.*}}
649 // memptr.convert: ; preds = %entry
650 // CHECK: insertvalue { ptr, i32 } undef, ptr %[[mp]], 0
651 // CHECK: insertvalue { ptr, i32 } %{{.*}}, i32 4, 1
652 // CHECK: br label
654 // memptr.converted: ; preds = %memptr.convert, %entry
655 // CHECK: phi { ptr, i32 } [ zeroinitializer, %{{.*}} ], [ {{.*}} ]
656 // CHECK: }
659 void (B2::*convertMultipleFuncToB2(void (Multiple::*mp)()))() {
660 // FIXME: cl emits warning C4407 on this code because of the representation
661 // change. We might want to do the same.
662 return static_cast<void (B2::*)()>(mp);
663 // FIXME: We should return ptr instead of i32 here. The ptrtoint cast prevents
664 // LLVM from optimizing away the branch. This is likely a bug in
665 // lib/CodeGen/Targets/X86.cpp with how we classify memptr types for returns.
667 // CHECK: define dso_local i32 @"?convertMultipleFuncToB2@@YAP8B2@@AEXXZP8Multiple@@AEXXZ@Z"{{.*}} {
668 // CHECK: store
669 // CHECK: %[[src:.*]] = load { ptr, i32 }, ptr %{{.*}}, align 4
670 // CHECK: extractvalue { ptr, i32 } %[[src]], 0
671 // CHECK: icmp ne ptr %{{.*}}, null
672 // CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}
674 // memptr.convert: ; preds = %entry
675 // CHECK: %[[fp:.*]] = extractvalue { ptr, i32 } %[[src]], 0
676 // CHECK: br label
678 // memptr.converted: ; preds = %memptr.convert, %entry
679 // CHECK: phi ptr [ null, %{{.*}} ], [ %[[fp]], %{{.*}} ]
680 // CHECK: }
683 namespace Test1 {
685 struct A { int a; };
686 struct B { int b; };
687 struct C : virtual A { int c; };
688 struct D : B, C { int d; };
690 void (D::*convertCToD(void (C::*mp)()))() {
691 return mp;
692 // CHECK: define dso_local void @"?convertCToD@Test1@@YAP8D@1@AEXXZP8C@1@AEXXZ@Z"{{.*}} {
693 // CHECK: store
694 // CHECK: load { ptr, i32, i32 }, ptr %{{.*}}, align 4
695 // CHECK: extractvalue { ptr, i32, i32 } %{{.*}}, 0
696 // CHECK: icmp ne ptr %{{.*}}, null
697 // CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}
699 // memptr.convert: ; preds = %entry
700 // CHECK: extractvalue { ptr, i32, i32 } %{{.*}}, 0
701 // CHECK: %[[nvoff:.*]] = extractvalue { ptr, i32, i32 } %{{.*}}, 1
702 // CHECK: %[[vbidx:.*]] = extractvalue { ptr, i32, i32 } %{{.*}}, 2
703 // CHECK: %[[is_nvbase:.*]] = icmp eq i32 %[[vbidx]], 0
704 // CHECK: %[[nv_disp:.*]] = add nsw i32 %[[nvoff]], 4
705 // CHECK: %[[nv_adj:.*]] = select i1 %[[is_nvbase]], i32 %[[nv_disp]], i32 0
706 // CHECK: %[[dst_adj:.*]] = select i1 %[[is_nvbase]], i32 4, i32 0
707 // CHECK: %[[adj:.*]] = sub nsw i32 %[[nv_adj]], %[[dst_adj]]
708 // CHECK: insertvalue { ptr, i32, i32 } undef, ptr {{.*}}, 0
709 // CHECK: insertvalue { ptr, i32, i32 } {{.*}}, i32 %[[adj]], 1
710 // CHECK: insertvalue { ptr, i32, i32 } {{.*}}, i32 {{.*}}, 2
711 // CHECK: br label
713 // memptr.converted: ; preds = %memptr.convert, %entry
714 // CHECK: phi { ptr, i32, i32 } [ { ptr null, i32 0, i32 -1 }, {{.*}} ], [ {{.*}} ]
715 // CHECK: }
720 namespace Test2 {
721 // Test that we dynamically convert between different null reps.
723 struct A { int a; };
724 struct B : A { int b; };
725 struct C : A {
726 int c;
727 virtual void hasVfPtr();
730 int A::*reinterpret(int B::*mp) {
731 return reinterpret_cast<int A::*>(mp);
732 // CHECK: define dso_local i32 @"?reinterpret@Test2@@YAPQA@1@HPQB@1@H@Z"{{.*}} {
733 // CHECK-NOT: select
734 // CHECK: ret i32
735 // CHECK: }
738 int A::*reinterpret(int C::*mp) {
739 return reinterpret_cast<int A::*>(mp);
740 // CHECK: define dso_local i32 @"?reinterpret@Test2@@YAPQA@1@HPQC@1@H@Z"{{.*}} {
741 // CHECK: %[[mp:.*]] = load i32, ptr
742 // CHECK: %[[cmp:.*]] = icmp ne i32 %[[mp]], 0
743 // CHECK: select i1 %[[cmp]], i32 %[[mp]], i32 -1
744 // CHECK: }
749 namespace Test3 {
750 // Make sure we cast 'this' to ptr before using GEP.
752 struct A {
753 int a;
754 int b;
757 int *load_data(A *a, int A::*mp) {
758 return &(a->*mp);
759 // CHECK-LABEL: define dso_local noundef ptr @"?load_data@Test3@@YAPAHPAUA@1@PQ21@H@Z"{{.*}} {
760 // CHECK: %[[a:.*]] = load ptr, ptr %{{.*}}, align 4
761 // CHECK: %[[mp:.*]] = load i32, ptr %{{.*}}, align 4
762 // CHECK: getelementptr inbounds i8, ptr %[[a]], i32 %[[mp]]
763 // CHECK: }
768 namespace Test4 {
770 struct A { virtual void f(); };
771 struct B { virtual void g(); };
772 struct C : A, B { virtual void g(); };
774 void (C::*getmp())() {
775 return &C::g;
777 // CHECK-LABEL: define dso_local i64 @"?getmp@Test4@@YAP8C@1@AEXXZXZ"()
778 // CHECK: store { ptr, i32 } { ptr @"??_9C@Test4@@$BA@AE", i32 4 }, ptr %{{.*}}
781 // CHECK-LABEL: define linkonce_odr x86_thiscallcc void @"??_9C@Test4@@$BA@AE"(ptr noundef %this, ...) {{.*}} comdat
782 // CHECK-NOT: getelementptr
783 // CHECK: load ptr, ptr %{{.*}}
784 // CHECK: getelementptr inbounds ptr, ptr %{{.*}}, i64 0
785 // CHECK-NOT: getelementptr
786 // CHECK: musttail call x86_thiscallcc void (ptr, ...) %
790 namespace pr20007 {
791 struct A {
792 void f();
793 void f(int);
795 struct B : public A {};
796 void test() { void (B::*a)() = &B::f; }
797 // CHECK-LABEL: define dso_local void @"?test@pr20007@@YAXXZ"
798 // CHECK: store ptr @"?f@A@pr20007@@QAEXXZ"
801 namespace pr20007_kw {
802 struct A {
803 void f();
804 void f(int);
806 struct __single_inheritance B;
807 struct B : public A {};
808 void test() { void (B::*a)() = &B::f; }
809 // CHECK-LABEL: define dso_local void @"?test@pr20007_kw@@YAXXZ"
810 // CHECK: store ptr @"?f@A@pr20007_kw@@QAEXXZ"
813 namespace pr20007_pragma {
814 struct A {
815 void f();
816 void f(int);
818 struct B : public A {};
819 void test() { (void)(void (B::*)()) &B::f; }
820 #pragma pointers_to_members(full_generality, virtual_inheritance)
821 static_assert(sizeof(int B::*) == 4, "");
822 static_assert(sizeof(int A::*) == 4, "");
823 #pragma pointers_to_members(best_case)
824 // CHECK-LABEL: define dso_local void @"?test@pr20007_pragma@@YAXXZ"
827 namespace pr20007_pragma2 {
828 struct A {
830 struct B : public A {
831 void f();
833 void test() { (void)&B::f; }
834 #pragma pointers_to_members(full_generality, virtual_inheritance)
835 static_assert(sizeof(int B::*) == 4, "");
836 static_assert(sizeof(int A::*) == 12, "");
837 #pragma pointers_to_members(best_case)
838 // CHECK-LABEL: define dso_local void @"?test@pr20007_pragma2@@YAXXZ"
841 namespace pr23823 {
842 struct Base { void Method(); };
843 struct Child : Base {};
844 void use(void (Child::*const &)());
845 void f() { use(&Child::Method); }
846 #pragma pointers_to_members(full_generality, virtual_inheritance)
847 static_assert(sizeof(int Base::*) == 4, "");
848 static_assert(sizeof(int Child::*) == 4, "");
849 #pragma pointers_to_members(best_case)
852 namespace pr19987 {
853 template <typename T>
854 struct S {
855 int T::*x;
858 struct U : S<U> {};
860 static_assert(sizeof(S<U>::x) == 12, "");
863 #else
864 struct __virtual_inheritance A;
865 #ifdef MEMFUN
866 int foo(A *a, int (A::*mp)()) {
867 return (a->*mp)(); // expected-error{{requires a complete class type}}
869 #else
870 int foo(A *a, int A::*mp) {
871 return a->*mp; // expected-error{{requires a complete class type}}
873 #endif
874 #endif
876 namespace pr23878 {
877 struct A { virtual void g(); };
878 struct B { virtual void f(); };
879 struct C : virtual B { void f(); };
880 struct D : A, C {};
882 typedef void (D::*DMemPtrTy)();
884 // CHECK-LABEL: define dso_local void @"?get_memptr@pr23878@@YAP8D@1@AEXXZXZ"
885 // CHECK: @"??_9C@pr23878@@$BA@AE", i32 0, i32 4
886 DMemPtrTy get_memptr() { return &D::f; }
889 class C {};
891 typedef void (C::*f)();
893 class CA : public C {
894 public:
895 void OnHelp(void);
896 int OnHelp(int);
899 // CHECK-LABEL: foo_fun
900 void foo_fun() {
901 // CHECK: store ptr @"?OnHelp@CA@@QAEXXZ", ptr
902 f func = (f)&CA::OnHelp;
904 namespace PR24703 {
905 struct S;
907 void f(int S::*&p) {}
908 // CHECK-LABEL: define dso_local void @"?f@PR24703@@YAXAAPQS@1@H@Z"(
911 namespace ReferenceToMPTWithIncompleteClass {
912 struct S;
913 struct J;
914 struct K;
915 extern K *k;
917 // CHECK-LABEL: @"?f@ReferenceToMPTWithIncompleteClass@@YAIAAPQS@1@H@Z"(
918 // CHECK: ret i32 12
919 unsigned f(int S::*&p) { return sizeof p; }
921 // CHECK-LABEL: @"?g@ReferenceToMPTWithIncompleteClass@@YA_NAAPQJ@1@H0@Z"(
922 bool g(int J::*&p, int J::*&q) { return p == q; }
924 // CHECK-LABEL: @"?h@ReferenceToMPTWithIncompleteClass@@YAHAAPQK@1@H@Z"(
925 int h(int K::*&p) { return k->*p; }
928 namespace PMFInTemplateArgument {
929 template <class C, int (C::*M)(int)>
930 void JSMethod();
931 class A {
932 int printd(int);
933 void printd();
935 void A::printd() { JSMethod<A, &A::printd>(); }
936 // CHECK-LABEL: @"??$JSMethod@VA@PMFInTemplateArgument@@$1?printd@12@AAEHH@Z@PMFInTemplateArgument@@YAXXZ"(
939 namespace MissingMSInheritanceAttr {
940 // This is a regression test for an assertion failure that occurred when
941 // compiling for C++17. The issue concerned a failure to propagate a
942 // MSInheritanceAttr attribute for the explicit template instantiation
943 // definition prior to it being required to complete the specialization
944 // definition in order to determine its alignment so as to resolve a
945 // lookup for a deallocation function for the virtual destructor.
946 template <typename>
947 class a;
948 struct b {
949 typedef void (a<int>::*f)();
950 f d;
952 template <typename>
953 class a {
954 virtual ~a();
955 b e;
957 extern template class a<int>;
958 template class a<int>;
959 #ifdef _WIN64
960 static_assert(sizeof(b::d) == 24, "");
961 static_assert(sizeof(void (a<int>::*)()) == 24, "");
962 #else
963 static_assert(sizeof(b::d) == 16, "");
964 static_assert(sizeof(void (a<int>::*)()) == 16, "");
965 #endif