[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / CodeGenCXX / microsoft-abi-member-pointers.cpp
blobc464c1c7071ea6906b9d3e47a2761caecce70958
1 // RUN: %clang_cc1 -no-opaque-pointers -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 -no-opaque-pointers -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 -no-opaque-pointers -std=c++11 -Wno-uninitialized -fno-rtti -emit-llvm %s -o - -triple=i386-pc-win32 -DINCOMPLETE_VIRTUAL -fms-extensions -verify
4 // RUN: %clang_cc1 -no-opaque-pointers -std=c++11 -Wno-uninitialized -fno-rtti -emit-llvm %s -o - -triple=i386-pc-win32 -DINCOMPLETE_VIRTUAL -DMEMFUN -fms-extensions -verify
6 namespace pr37399 {
7 template <typename T>
8 struct Functor {
9 void (T::*PtrToMemberFunction)();
11 // CHECK-DAG: %"struct.pr37399::Functor" = type { i8* }
13 template <typename SomeType>
14 class SimpleDerivedFunctor;
15 template <typename SomeType>
16 class SimpleDerivedFunctor : public Functor<SimpleDerivedFunctor<SomeType>> {};
17 // CHECK-DAG: %"class.pr37399::SimpleDerivedFunctor" = type { %"struct.pr37399::Functor" }
19 SimpleDerivedFunctor<void> SimpleFunctor;
20 // CHECK-DAG: @"?SimpleFunctor@pr37399@@3V?$SimpleDerivedFunctor@X@1@A" = dso_local global %"class.pr37399::SimpleDerivedFunctor" zeroinitializer, align 4
22 short Global = 0;
23 template <typename SomeType>
24 class DerivedFunctor;
25 template <typename SomeType>
26 class DerivedFunctor
27 : public Functor<DerivedFunctor<void>> {
28 public:
29 void Foo() {
30 Global = 42;
34 class MultipleBase {
35 public:
36 MultipleBase() : Value() {}
37 short Value;
39 // CHECK-DAG: %"class.pr37399::MultipleBase" = type { i16 }
41 template <typename SomeType>
42 class MultiplyDerivedFunctor;
43 template <typename SomeType>
44 class MultiplyDerivedFunctor
45 : public Functor<MultiplyDerivedFunctor<void>>,
46 public MultipleBase {
47 public:
48 void Foo() {
49 MultipleBase::Value = 42*2;
53 class VirtualBase {
54 public:
55 VirtualBase() : Value() {}
56 short Value;
58 // CHECK-DAG: %"class.pr37399::VirtualBase" = type { i16 }
60 template <typename SomeType>
61 class VirtBaseFunctor
62 : public Functor<SomeType>,
63 public virtual VirtualBase{};
64 template <typename SomeType>
65 class VirtuallyDerivedFunctor;
66 template <typename SomeType>
67 class VirtuallyDerivedFunctor
68 : public VirtBaseFunctor<VirtuallyDerivedFunctor<void>>,
69 public virtual VirtualBase {
70 public:
71 void Foo() {
72 VirtualBase::Value = 42*3;
75 } // namespace pr37399
77 pr37399::DerivedFunctor<int> BFunctor;
78 // CHECK-DAG: @"?BFunctor@@3V?$DerivedFunctor@H@pr37399@@A" = dso_local global %"[[BFUNCTOR:class.pr37399::DerivedFunctor(\.[0-9]+)?]]" zeroinitializer, align 8
79 // CHECK-DAG: %"[[BFUNCTOR]]" = type { %"[[BFUNCTORBASE:struct.pr37399::Functor(\.[0-9]+)?]]" }
80 // CHECK-DAG: %"[[BFUNCTORBASE]]" = type { { i8*, i32, i32, i32 } }
81 pr37399::DerivedFunctor<void> AFunctor;
82 // CHECK-DAG: @"?AFunctor@@3V?$DerivedFunctor@X@pr37399@@A" = dso_local global %"[[AFUNCTOR:class.pr37399::DerivedFunctor(\.[0-9]+)?]]" zeroinitializer, align 8
83 // CHECK-DAG: %"[[AFUNCTOR]]" = type { %"[[AFUNCTORBASE:struct.pr37399::Functor(\.[0-9]+)?]]" }
84 // CHECK-DAG: %"[[AFUNCTORBASE]]" = type { { i8*, i32, i32, i32 } }
86 pr37399::MultiplyDerivedFunctor<int> DFunctor;
87 // CHECK-DAG: @"?DFunctor@@3V?$MultiplyDerivedFunctor@H@pr37399@@A" = dso_local global %"[[DFUNCTOR:class.pr37399::MultiplyDerivedFunctor(\.[0-9]+)?]]" zeroinitializer, align 8
88 // CHECK-DAG: %"[[DFUNCTOR]]" = type { %"[[DFUNCTORBASE:struct.pr37399::Functor(\.[0-9]+)?]]", %"class.pr37399::MultipleBase", [6 x i8] }
89 // CHECK-DAG: %"[[DFUNCTORBASE]]" = type { { i8*, i32, i32, i32 } }
90 pr37399::MultiplyDerivedFunctor<void> CFunctor;
91 // CHECK-DAG: @"?CFunctor@@3V?$MultiplyDerivedFunctor@X@pr37399@@A" = dso_local global %"[[CFUNCTOR:class.pr37399::MultiplyDerivedFunctor(\.[0-9]+)?]]" zeroinitializer, align 8
92 // CHECK-DAG: %"[[CFUNCTOR]]" = type { %"[[CFUNCTORBASE:struct.pr37399::Functor(\.[0-9]+)?]]", %"class.pr37399::MultipleBase", [6 x i8] }
93 // CHECK-DAG: %"[[CFUNCTORBASE]]" = type { { i8*, i32, i32, i32 } }
95 pr37399::VirtuallyDerivedFunctor<int> FFunctor;
96 // CHECK-DAG: @"?FFunctor@@3V?$VirtuallyDerivedFunctor@H@pr37399@@A" = dso_local global %"[[FFUNCTOR:class.pr37399::VirtuallyDerivedFunctor(\.[0-9]+)?]]" zeroinitializer, align 8
97 // CHECK-DAG: %"[[FFUNCTOR]]" = type { %"class.pr37399::VirtBaseFunctor.base", %"class.pr37399::VirtualBase" }
98 pr37399::VirtuallyDerivedFunctor<void> EFunctor;
99 // CHECK-DAG: @"?EFunctor@@3V?$VirtuallyDerivedFunctor@X@pr37399@@A" = dso_local global %"[[EFUNCTOR:class.pr37399::VirtuallyDerivedFunctor(\.[0-9]+)?]]" zeroinitializer, align 8
100 // CHECK-DAG: %"[[EFUNCTOR]]" = type { %"class.pr37399::VirtBaseFunctor.base", %"class.pr37399::VirtualBase" }
102 // CHECK-DAG: %"class.pr37399::VirtBaseFunctor.base" = type <{ %"[[VFUNCTORBASE:struct.pr37399::Functor(\.[0-9]+)?]]", i32*, [4 x i8] }>
103 // CHECK-DAG: %"[[VFUNCTORBASE]]" = type { { i8*, i32, i32, i32 } }
105 namespace pr37399 {
106 void SingleInheritanceFnPtrCall() {
107 BFunctor.PtrToMemberFunction = &DerivedFunctor<void>::Foo;
108 (AFunctor.*(BFunctor.PtrToMemberFunction))();
110 void MultipleInheritanceFnPtrCall() {
111 DFunctor.PtrToMemberFunction = &MultiplyDerivedFunctor<void>::Foo;
112 Global = CFunctor.MultipleBase::Value;
113 (CFunctor.*(DFunctor.PtrToMemberFunction))();
114 Global = CFunctor.MultipleBase::Value;
116 void VirtualInheritanceFnPtrCall() {
117 FFunctor.PtrToMemberFunction = &VirtuallyDerivedFunctor<void>::Foo;
118 Global = EFunctor.VirtualBase::Value;
119 (EFunctor.*(FFunctor.PtrToMemberFunction))();
120 Global = EFunctor.VirtualBase::Value;
122 } // namespace pr37399
124 namespace pr43803 {
125 // This case is interesting because it exercises conversion between member
126 // pointer types when emitting constants.
128 struct B;
129 struct C { int B::*option; };
130 extern const C table[3];
131 struct A {
132 int x, y;
133 // Test the indirect case.
134 struct {
135 int z;
138 struct B : A {};
139 const C table[] = {
140 {&B::x},
141 {&B::y},
142 {&B::z},
145 // CHECK: @"?table@pr43803@@3QBUC@1@B" = dso_local constant [3 x %"struct.pr43803::C"]
146 // CHECK-SAME: [%"struct.pr43803::C" { { i32, i32, i32 } zeroinitializer, [4 x i8] undef },
147 // CHECK-SAME: %"struct.pr43803::C" { { i32, i32, i32 } { i32 4, i32 0, i32 0 }, [4 x i8] undef },
148 // CHECK-SAME: %"struct.pr43803::C" { { i32, i32, i32 } { i32 8, i32 0, i32 0 }, [4 x i8] undef }]
151 namespace pr48687 {
152 template <typename T> struct A {
153 T value;
154 static constexpr auto address = &A<T>::value;
156 extern template class A<float>;
157 template class A<float>;
158 // CHECK: @"?address@?$A@M@pr48687@@2QQ12@MQ12@" = weak_odr dso_local constant i32 0, comdat, align 4
161 struct PR26313_Y;
162 typedef void (PR26313_Y::*PR26313_FUNC)();
163 struct PR26313_X {
164 PR26313_FUNC *ptr;
165 PR26313_X();
167 PR26313_X::PR26313_X() {}
168 void PR26313_f(PR26313_FUNC *p) { delete p; }
170 struct PR26313_Z;
171 int PR26313_Z::**a = nullptr;
172 int PR26313_Z::*b = *a;
173 // CHECK-DAG: @"?a@@3PAPQPR26313_Z@@HA" = dso_local global %0* null, align 4
174 // CHECK-DAG: @"?b@@3PQPR26313_Z@@HQ1@" = dso_local global { i32, i32, i32 } { i32 0, i32 0, i32 -1 }, align 4
176 namespace PR20947 {
177 struct A;
178 int A::**a = nullptr;
179 // CHECK-DAG: @"?a@PR20947@@3PAPQA@1@HA" = dso_local global %{{.*}}* null, align 4
181 struct B;
182 int B::*&b = b;
183 // CHECK-DAG: @"?b@PR20947@@3AAPQB@1@HA" = dso_local global %{{.*}}* null, align 4
186 namespace PR20017 {
187 template <typename T>
188 struct A {
189 int T::*m_fn1() { return nullptr; }
191 struct B;
192 auto a = &A<B>::m_fn1;
193 // CHECK-DAG: @"?a@PR20017@@3P8?$A@UB@PR20017@@@1@AEPQB@1@HXZQ21@" = dso_local global i8* bitcast ({ i32, i32, i32 } ({{.*}}*)* @"?m_fn1@?$A@UB@PR20017@@@PR20017@@QAEPQB@2@HXZ" to i8*), align 4
196 #ifndef INCOMPLETE_VIRTUAL
197 struct B1 {
198 void foo();
199 int b;
201 struct B2 {
202 int b2;
203 void foo();
205 struct Single : B1 {
206 void foo();
208 struct Multiple : B1, B2 {
209 int m;
210 void foo();
212 struct Virtual : virtual B1 {
213 int v;
214 void foo();
217 struct POD {
218 int a;
219 int b;
222 struct Polymorphic {
223 virtual void myVirtual();
224 int a;
225 int b;
228 // This class uses the virtual inheritance model, yet its vbptr offset is not 0.
229 // We still use zero for the null field offset, despite it being a valid field
230 // offset.
231 struct NonZeroVBPtr : POD, Virtual {
232 int n;
233 void foo();
236 struct Unspecified;
237 struct UnspecSingle;
239 // Check that we can lower the LLVM types and get the null initializers right.
240 int Single ::*s_d_memptr;
241 int Polymorphic::*p_d_memptr;
242 int Multiple ::*m_d_memptr;
243 int Virtual ::*v_d_memptr;
244 int NonZeroVBPtr::*n_d_memptr;
245 int Unspecified::*u_d_memptr;
246 int UnspecSingle::*us_d_memptr;
247 // CHECK: @"?s_d_memptr@@3PQSingle@@HQ1@" = dso_local global i32 -1, align 4
248 // CHECK: @"?p_d_memptr@@3PQPolymorphic@@HQ1@" = dso_local global i32 0, align 4
249 // CHECK: @"?m_d_memptr@@3PQMultiple@@HQ1@" = dso_local global i32 -1, align 4
250 // CHECK: @"?v_d_memptr@@3PQVirtual@@HQ1@" = dso_local global { i32, i32 }
251 // CHECK: { i32 0, i32 -1 }, align 4
252 // CHECK: @"?n_d_memptr@@3PQNonZeroVBPtr@@HQ1@" = dso_local global { i32, i32 }
253 // CHECK: { i32 0, i32 -1 }, align 4
254 // CHECK: @"?u_d_memptr@@3PQUnspecified@@HQ1@" = dso_local global { i32, i32, i32 }
255 // CHECK: { i32 0, i32 0, i32 -1 }, align 4
256 // CHECK: @"?us_d_memptr@@3PQUnspecSingle@@HQ1@" = dso_local global { i32, i32, i32 }
257 // CHECK: { i32 0, i32 0, i32 -1 }, align 4
259 void (Single ::*s_f_memptr)();
260 void (Multiple::*m_f_memptr)();
261 void (Virtual ::*v_f_memptr)();
262 // CHECK: @"?s_f_memptr@@3P8Single@@AEXXZQ1@" = dso_local global i8* null, align 4
263 // CHECK: @"?m_f_memptr@@3P8Multiple@@AEXXZQ1@" = dso_local global { i8*, i32 } zeroinitializer, align 4
264 // CHECK: @"?v_f_memptr@@3P8Virtual@@AEXXZQ1@" = dso_local global { i8*, i32, i32 } zeroinitializer, align 4
266 // We can define Unspecified after locking in the inheritance model.
267 struct Unspecified : Multiple, Virtual {
268 void foo();
269 int u;
272 struct UnspecSingle {
273 void foo();
276 // Test memptr emission in a constant expression.
277 namespace Const {
278 void (Single ::*s_f_mp)() = &Single::foo;
279 void (Multiple ::*m_f_mp)() = &B2::foo;
280 void (Virtual ::*v_f_mp)() = &Virtual::foo;
281 void (Unspecified::*u_f_mp)() = &Unspecified::foo;
282 void (UnspecSingle::*us_f_mp)() = &UnspecSingle::foo;
283 // CHECK: @"?s_f_mp@Const@@3P8Single@@AEXXZQ2@" =
284 // CHECK: global i8* bitcast ({{.*}} @"?foo@Single@@QAEXXZ" to i8*), align 4
285 // CHECK: @"?m_f_mp@Const@@3P8Multiple@@AEXXZQ2@" =
286 // CHECK: global { i8*, i32 } { i8* bitcast ({{.*}} @"?foo@B2@@QAEXXZ" to i8*), i32 4 }, align 4
287 // CHECK: @"?v_f_mp@Const@@3P8Virtual@@AEXXZQ2@" =
288 // CHECK: global { i8*, i32, i32 } { i8* bitcast ({{.*}} @"?foo@Virtual@@QAEXXZ" to i8*), i32 0, i32 0 }, align 4
289 // CHECK: @"?u_f_mp@Const@@3P8Unspecified@@AEXXZQ2@" =
290 // CHECK: global { i8*, i32, i32, i32 } { i8* bitcast ({{.*}} @"?foo@Unspecified@@QAEXXZ" to i8*), i32 0, i32 0, i32 0 }, align 4
291 // CHECK: @"?us_f_mp@Const@@3P8UnspecSingle@@AEXXZQ2@" =
292 // CHECK: global { i8*, i32, i32, i32 } { i8* bitcast ({{.*}} @"?foo@UnspecSingle@@QAEXXZ" to i8*), i32 0, i32 0, i32 0 }, align 4
295 namespace CastParam {
296 // This exercises ConstExprEmitter instead of ValueDecl::evaluateValue. The
297 // extra reinterpret_cast for the parameter type requires more careful folding.
298 // FIXME: Or does it? If reinterpret_casts are no-ops, we should be able to
299 // strip them in evaluateValue() and just proceed as normal with an APValue.
300 struct A {
301 int a;
302 void foo(A *p);
304 struct B { int b; };
305 struct C : B, A { int c; };
307 void (A::*ptr1)(void *) = (void (A::*)(void *)) &A::foo;
308 // CHECK: @"?ptr1@CastParam@@3P8A@1@AEXPAX@ZQ21@" =
309 // CHECK: global i8* bitcast (void ({{.*}})* @"?foo@A@CastParam@@QAEXPAU12@@Z" to i8*), align 4
311 // Try a reinterpret_cast followed by a memptr conversion.
312 void (C::*ptr2)(void *) = (void (C::*)(void *)) (void (A::*)(void *)) &A::foo;
313 // CHECK: @"?ptr2@CastParam@@3P8C@1@AEXPAX@ZQ21@" =
314 // CHECK: global { i8*, i32 } { i8* bitcast (void ({{.*}})* @"?foo@A@CastParam@@QAEXPAU12@@Z" to i8*), i32 4 }, align 4
316 void (C::*ptr3)(void *) = (void (C::*)(void *)) (void (A::*)(void *)) (void (A::*)(A *)) 0;
317 // CHECK: @"?ptr3@CastParam@@3P8C@1@AEXPAX@ZQ21@" =
318 // CHECK: global { i8*, i32 } zeroinitializer, align 4
320 struct D : C {
321 virtual void isPolymorphic();
322 int d;
325 // Try a cast that changes the inheritance model. Null for D is 0, but null for
326 // C is -1. We need the cast to long in order to hit the non-APValue path.
327 int C::*ptr4 = (int C::*) (int D::*) (long D::*) 0;
328 // CHECK: @"?ptr4@CastParam@@3PQC@1@HQ21@" = dso_local global i32 -1, align 4
330 // MSVC rejects this but we accept it.
331 int C::*ptr5 = (int C::*) (long D::*) 0;
332 // CHECK: @"?ptr5@CastParam@@3PQC@1@HQ21@" = dso_local global i32 -1, align 4
335 struct UnspecWithVBPtr;
336 int UnspecWithVBPtr::*forceUnspecWithVBPtr;
337 struct UnspecWithVBPtr : B1, virtual B2 {
338 int u;
339 void foo();
342 // Test emitting non-virtual member pointers in a non-constexpr setting.
343 void EmitNonVirtualMemberPointers() {
344 void (Single ::*s_f_memptr)() = &Single::foo;
345 void (Multiple ::*m_f_memptr)() = &Multiple::foo;
346 void (Virtual ::*v_f_memptr)() = &Virtual::foo;
347 void (Unspecified::*u_f_memptr)() = &Unspecified::foo;
348 void (UnspecWithVBPtr::*u2_f_memptr)() = &UnspecWithVBPtr::foo;
349 // CHECK: define dso_local void @"?EmitNonVirtualMemberPointers@@YAXXZ"() {{.*}} {
350 // CHECK: alloca i8*, align 4
351 // CHECK: alloca { i8*, i32 }, align 4
352 // CHECK: alloca { i8*, i32, i32 }, align 4
353 // CHECK: alloca { i8*, i32, i32, i32 }, align 4
354 // CHECK: store i8* bitcast (void (%{{.*}}*)* @"?foo@Single@@QAEXXZ" to i8*), i8** %{{.*}}, align 4
355 // CHECK: store { i8*, i32 }
356 // CHECK: { i8* bitcast (void (%{{.*}}*)* @"?foo@Multiple@@QAEXXZ" to i8*), i32 0 },
357 // CHECK: { i8*, i32 }* %{{.*}}, align 4
358 // CHECK: store { i8*, i32, i32 }
359 // CHECK: { i8* bitcast (void (%{{.*}}*)* @"?foo@Virtual@@QAEXXZ" to i8*), i32 0, i32 0 },
360 // CHECK: { i8*, i32, i32 }* %{{.*}}, align 4
361 // CHECK: store { i8*, i32, i32, i32 }
362 // CHECK: { i8* bitcast (void (%{{.*}}*)* @"?foo@Unspecified@@QAEXXZ" to i8*), i32 0, i32 0, i32 0 },
363 // CHECK: { i8*, i32, i32, i32 }* %{{.*}}, align 4
364 // CHECK: store { i8*, i32, i32, i32 }
365 // CHECK: { i8* bitcast (void (%{{.*}}*)* @"?foo@UnspecWithVBPtr@@QAEXXZ" to i8*),
366 // CHECK: i32 0, i32 0, i32 0 },
367 // CHECK: { i8*, i32, i32, i32 }* %{{.*}}, align 4
368 // CHECK: ret void
369 // CHECK: }
372 void podMemPtrs() {
373 int POD::*memptr;
374 memptr = &POD::a;
375 memptr = &POD::b;
376 if (memptr)
377 memptr = 0;
378 // Check that member pointers use the right offsets and that null is -1.
379 // CHECK: define dso_local void @"?podMemPtrs@@YAXXZ"() {{.*}} {
380 // CHECK: %[[memptr:.*]] = alloca i32, align 4
381 // CHECK-NEXT: store i32 0, i32* %[[memptr]], align 4
382 // CHECK-NEXT: store i32 4, i32* %[[memptr]], align 4
383 // CHECK-NEXT: %[[memptr_val:.*]] = load i32, i32* %[[memptr]], align 4
384 // CHECK-NEXT: %{{.*}} = icmp ne i32 %[[memptr_val]], -1
385 // CHECK-NEXT: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}
386 // CHECK: store i32 -1, i32* %[[memptr]], align 4
387 // CHECK: ret void
388 // CHECK: }
391 void polymorphicMemPtrs() {
392 int Polymorphic::*memptr;
393 memptr = &Polymorphic::a;
394 memptr = &Polymorphic::b;
395 if (memptr)
396 memptr = 0;
397 // Member pointers for polymorphic classes include the vtable slot in their
398 // offset and use 0 to represent null.
399 // CHECK: define dso_local void @"?polymorphicMemPtrs@@YAXXZ"() {{.*}} {
400 // CHECK: %[[memptr:.*]] = alloca i32, align 4
401 // CHECK-NEXT: store i32 4, i32* %[[memptr]], align 4
402 // CHECK-NEXT: store i32 8, i32* %[[memptr]], align 4
403 // CHECK-NEXT: %[[memptr_val:.*]] = load i32, i32* %[[memptr]], align 4
404 // CHECK-NEXT: %{{.*}} = icmp ne i32 %[[memptr_val]], 0
405 // CHECK-NEXT: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}
406 // CHECK: store i32 0, i32* %[[memptr]], align 4
407 // CHECK: ret void
408 // CHECK: }
411 bool nullTestDataUnspecified(int Unspecified::*mp) {
412 return mp;
413 // CHECK: define dso_local noundef zeroext i1 @"?nullTestDataUnspecified@@YA_NPQUnspecified@@H@Z"{{.*}} {
414 // CHECK: %{{.*}} = load { i32, i32, i32 }, { i32, i32, i32 }* %{{.*}}, align 4
415 // CHECK: store { i32, i32, i32 } {{.*}} align 4
416 // CHECK: %[[mp:.*]] = load { i32, i32, i32 }, { i32, i32, i32 }* %{{.*}}, align 4
417 // CHECK: %[[mp0:.*]] = extractvalue { i32, i32, i32 } %[[mp]], 0
418 // CHECK: %[[cmp0:.*]] = icmp ne i32 %[[mp0]], 0
419 // CHECK: %[[mp1:.*]] = extractvalue { i32, i32, i32 } %[[mp]], 1
420 // CHECK: %[[cmp1:.*]] = icmp ne i32 %[[mp1]], 0
421 // CHECK: %[[and0:.*]] = or i1 %[[cmp0]], %[[cmp1]]
422 // CHECK: %[[mp2:.*]] = extractvalue { i32, i32, i32 } %[[mp]], 2
423 // CHECK: %[[cmp2:.*]] = icmp ne i32 %[[mp2]], -1
424 // CHECK: %[[and1:.*]] = or i1 %[[and0]], %[[cmp2]]
425 // CHECK: ret i1 %[[and1]]
426 // CHECK: }
428 // Pass this large type indirectly.
429 // X64-LABEL: define dso_local noundef zeroext i1 @"?nullTestDataUnspecified@@
430 // X64: ({ i32, i32, i32 }* noundef %0)
433 bool nullTestFunctionUnspecified(void (Unspecified::*mp)()) {
434 return mp;
435 // CHECK: define dso_local noundef zeroext i1 @"?nullTestFunctionUnspecified@@YA_NP8Unspecified@@AEXXZ@Z"{{.*}} {
436 // CHECK: %{{.*}} = load { i8*, i32, i32, i32 }, { i8*, i32, i32, i32 }* %{{.*}}, align 4
437 // CHECK: store { i8*, i32, i32, i32 } {{.*}} align 4
438 // CHECK: %[[mp:.*]] = load { i8*, i32, i32, i32 }, { i8*, i32, i32, i32 }* %{{.*}}, align 4
439 // CHECK: %[[mp0:.*]] = extractvalue { i8*, i32, i32, i32 } %[[mp]], 0
440 // CHECK: %[[cmp0:.*]] = icmp ne i8* %[[mp0]], null
441 // CHECK: ret i1 %[[cmp0]]
442 // CHECK: }
445 int loadDataMemberPointerVirtual(Virtual *o, int Virtual::*memptr) {
446 return o->*memptr;
447 // Test that we can unpack this aggregate member pointer and load the member
448 // data pointer.
449 // CHECK: define dso_local noundef i32 @"?loadDataMemberPointerVirtual@@YAHPAUVirtual@@PQ1@H@Z"{{.*}} {
450 // CHECK: %[[o:.*]] = load %{{.*}}*, %{{.*}}** %{{.*}}, align 4
451 // CHECK: %[[memptr:.*]] = load { i32, i32 }, { i32, i32 }* %{{.*}}, align 4
452 // CHECK: %[[memptr0:.*]] = extractvalue { i32, i32 } %[[memptr:.*]], 0
453 // CHECK: %[[memptr1:.*]] = extractvalue { i32, i32 } %[[memptr:.*]], 1
454 // CHECK: %[[v6:.*]] = bitcast %{{.*}}* %[[o]] to i8*
455 // CHECK: %[[vbptr:.*]] = getelementptr inbounds i8, i8* %[[v6]], i32 0
456 // CHECK: %[[vbptr_a:.*]] = bitcast i8* %[[vbptr]] to i32**
457 // CHECK: %[[vbtable:.*]] = load i32*, i32** %[[vbptr_a:.*]]
458 // CHECK: %[[memptr1_shr:.*]] = ashr exact i32 %[[memptr1]], 2
459 // CHECK: %[[v7:.*]] = getelementptr inbounds i32, i32* %[[vbtable]], i32 %[[memptr1_shr]]
460 // CHECK: %[[vbase_offs:.*]] = load i32, i32* %[[v7]]
461 // CHECK: %[[v10:.*]] = getelementptr inbounds i8, i8* %[[vbptr]], i32 %[[vbase_offs]]
462 // CHECK: %[[offset:.*]] = getelementptr inbounds i8, i8* %[[v10]], i32 %[[memptr0]]
463 // CHECK: %[[v11:.*]] = bitcast i8* %[[offset]] to i32*
464 // CHECK: %[[v12:.*]] = load i32, i32* %[[v11]]
465 // CHECK: ret i32 %[[v12]]
466 // CHECK: }
468 // A two-field data memptr on x64 gets coerced to i64 and is passed in a
469 // register or memory.
470 // X64-LABEL: define dso_local noundef i32 @"?loadDataMemberPointerVirtual@@YAHPEAUVirtual@@PEQ1@H@Z"
471 // X64: (%struct.Virtual* noundef %o, i64 %memptr.coerce)
474 int loadDataMemberPointerUnspecified(Unspecified *o, int Unspecified::*memptr) {
475 return o->*memptr;
476 // Test that we can unpack this aggregate member pointer and load the member
477 // data pointer.
478 // CHECK: define dso_local noundef i32 @"?loadDataMemberPointerUnspecified@@YAHPAUUnspecified@@PQ1@H@Z"{{.*}} {
479 // CHECK: %[[o:.*]] = load %{{.*}}*, %{{.*}}** %{{.*}}, align 4
480 // CHECK: %[[memptr:.*]] = load { i32, i32, i32 }, { i32, i32, i32 }* %{{.*}}, align 4
481 // CHECK: %[[memptr0:.*]] = extractvalue { i32, i32, i32 } %[[memptr:.*]], 0
482 // CHECK: %[[memptr1:.*]] = extractvalue { i32, i32, i32 } %[[memptr:.*]], 1
483 // CHECK: %[[memptr2:.*]] = extractvalue { i32, i32, i32 } %[[memptr:.*]], 2
484 // CHECK: %[[base:.*]] = bitcast %{{.*}}* %[[o]] to i8*
485 // CHECK: %[[is_vbase:.*]] = icmp ne i32 %[[memptr2]], 0
486 // CHECK: br i1 %[[is_vbase]], label %[[vadjust:.*]], label %[[skip:.*]]
488 // CHECK: [[vadjust]]
489 // CHECK: %[[vbptr:.*]] = getelementptr inbounds i8, i8* %[[base]], i32 %[[memptr1]]
490 // CHECK: %[[vbptr_a:.*]] = bitcast i8* %[[vbptr]] to i32**
491 // CHECK: %[[vbtable:.*]] = load i32*, i32** %[[vbptr_a:.*]]
492 // CHECK: %[[memptr2_shr:.*]] = ashr exact i32 %[[memptr2]], 2
493 // CHECK: %[[v7:.*]] = getelementptr inbounds i32, i32* %[[vbtable]], i32 %[[memptr2_shr]]
494 // CHECK: %[[vbase_offs:.*]] = load i32, i32* %[[v7]]
495 // CHECK: %[[base_adj:.*]] = getelementptr inbounds i8, i8* %[[vbptr]], i32 %[[vbase_offs]]
497 // CHECK: [[skip]]
498 // CHECK: %[[new_base:.*]] = phi i8* [ %[[base]], %{{.*}} ], [ %[[base_adj]], %[[vadjust]] ]
499 // CHECK: %[[offset:.*]] = getelementptr inbounds i8, i8* %[[new_base]], i32 %[[memptr0]]
500 // CHECK: %[[v11:.*]] = bitcast i8* %[[offset]] to i32*
501 // CHECK: %[[v12:.*]] = load i32, i32* %[[v11]]
502 // CHECK: ret i32 %[[v12]]
503 // CHECK: }
506 void callMemberPointerSingle(Single *o, void (Single::*memptr)()) {
507 (o->*memptr)();
508 // Just look for an indirect thiscall.
509 // CHECK: define dso_local void @"?callMemberPointerSingle@@{{.*}} {{.*}} {
510 // CHECK: call x86_thiscallcc void %{{.*}}(%{{.*}} %{{.*}})
511 // CHECK: ret void
512 // CHECK: }
514 // X64-LABEL: define dso_local void @"?callMemberPointerSingle@@
515 // X64: (%struct.Single* noundef %o, i8* %memptr)
516 // X64: bitcast i8* %{{[^ ]*}} to void (%struct.Single*)*
517 // X64: ret void
520 void callMemberPointerMultiple(Multiple *o, void (Multiple::*memptr)()) {
521 (o->*memptr)();
522 // CHECK: define dso_local void @"?callMemberPointerMultiple@@{{.*}} {
523 // CHECK: %[[memptr0:.*]] = extractvalue { i8*, i32 } %{{.*}}, 0
524 // CHECK: %[[memptr1:.*]] = extractvalue { i8*, i32 } %{{.*}}, 1
525 // CHECK: %[[this_adjusted:.*]] = getelementptr inbounds i8, i8* %{{.*}}, i32 %[[memptr1]]
526 // CHECK: %[[this:.*]] = bitcast i8* %[[this_adjusted]] to {{.*}}
527 // CHECK: %[[fptr:.*]] = bitcast i8* %[[memptr0]] to {{.*}}
528 // CHECK: call x86_thiscallcc void %[[fptr]](%{{.*}} %[[this]])
529 // CHECK: ret void
530 // CHECK: }
533 void callMemberPointerVirtualBase(Virtual *o, void (Virtual::*memptr)()) {
534 (o->*memptr)();
535 // This shares a lot with virtual data member pointers.
536 // CHECK: define dso_local void @"?callMemberPointerVirtualBase@@{{.*}} {
537 // CHECK: %[[memptr0:.*]] = extractvalue { i8*, i32, i32 } %{{.*}}, 0
538 // CHECK: %[[memptr1:.*]] = extractvalue { i8*, i32, i32 } %{{.*}}, 1
539 // CHECK: %[[memptr2:.*]] = extractvalue { i8*, i32, i32 } %{{.*}}, 2
540 // CHECK: %[[vbptr:.*]] = getelementptr inbounds i8, i8* %{{.*}}, i32 0
541 // CHECK: %[[vbptr_a:.*]] = bitcast i8* %[[vbptr]] to i32**
542 // CHECK: %[[vbtable:.*]] = load i32*, i32** %[[vbptr_a:.*]]
543 // CHECK: %[[memptr2_shr:.*]] = ashr exact i32 %[[memptr2]], 2
544 // CHECK: %[[v7:.*]] = getelementptr inbounds i32, i32* %[[vbtable]], i32 %[[memptr2_shr]]
545 // CHECK: %[[vbase_offs:.*]] = load i32, i32* %[[v7]]
546 // CHECK: %[[v10:.*]] = getelementptr inbounds i8, i8* %[[vbptr]], i32 %[[vbase_offs]]
547 // CHECK: %[[this_adjusted:.*]] = getelementptr inbounds i8, i8* %[[v10]], i32 %[[memptr1]]
548 // CHECK: %[[fptr:.*]] = bitcast i8* %[[memptr0]] to void ({{.*}})
549 // CHECK: %[[this:.*]] = bitcast i8* %[[this_adjusted]] to {{.*}}
550 // CHECK: call x86_thiscallcc void %[[fptr]](%{{.*}} %[[this]])
551 // CHECK: ret void
552 // CHECK: }
555 bool compareSingleFunctionMemptr(void (Single::*l)(), void (Single::*r)()) {
556 return l == r;
557 // Should only be one comparison here.
558 // CHECK: define dso_local noundef zeroext i1 @"?compareSingleFunctionMemptr@@YA_NP8Single@@AEXXZ0@Z"{{.*}} {
559 // CHECK-NOT: icmp
560 // CHECK: %[[r:.*]] = icmp eq
561 // CHECK-NOT: icmp
562 // CHECK: ret i1 %[[r]]
563 // CHECK: }
565 // X64-LABEL: define dso_local noundef zeroext i1 @"?compareSingleFunctionMemptr@@
566 // X64: (i8* %{{[^,]*}}, i8* %{{[^)]*}})
569 bool compareNeqSingleFunctionMemptr(void (Single::*l)(), void (Single::*r)()) {
570 return l != r;
571 // Should only be one comparison here.
572 // CHECK: define dso_local noundef zeroext i1 @"?compareNeqSingleFunctionMemptr@@YA_NP8Single@@AEXXZ0@Z"{{.*}} {
573 // CHECK-NOT: icmp
574 // CHECK: %[[r:.*]] = icmp ne
575 // CHECK-NOT: icmp
576 // CHECK: ret i1 %[[r]]
577 // CHECK: }
580 bool unspecFuncMemptrEq(void (Unspecified::*l)(), void (Unspecified::*r)()) {
581 return l == r;
582 // CHECK: define dso_local noundef zeroext i1 @"?unspecFuncMemptrEq@@YA_NP8Unspecified@@AEXXZ0@Z"{{.*}} {
583 // CHECK: %[[lhs0:.*]] = extractvalue { i8*, i32, i32, i32 } %[[l:.*]], 0
584 // CHECK: %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[r:.*]], 0
585 // CHECK: %[[cmp0:.*]] = icmp eq i8* %[[lhs0]], %{{.*}}
586 // CHECK: %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[l]], 1
587 // CHECK: %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[r]], 1
588 // CHECK: %[[cmp1:.*]] = icmp eq i32
589 // CHECK: %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[l]], 2
590 // CHECK: %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[r]], 2
591 // CHECK: %[[cmp2:.*]] = icmp eq i32
592 // CHECK: %[[res12:.*]] = and i1 %[[cmp1]], %[[cmp2]]
593 // CHECK: %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[l]], 3
594 // CHECK: %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[r]], 3
595 // CHECK: %[[cmp3:.*]] = icmp eq i32
596 // CHECK: %[[res123:.*]] = and i1 %[[res12]], %[[cmp3]]
597 // CHECK: %[[iszero:.*]] = icmp eq i8* %[[lhs0]], null
598 // CHECK: %[[bits_or_null:.*]] = or i1 %[[res123]], %[[iszero]]
599 // CHECK: %{{.*}} = and i1 %[[bits_or_null]], %[[cmp0]]
600 // CHECK: ret i1 %{{.*}}
601 // CHECK: }
603 // X64-LABEL: define dso_local noundef zeroext i1 @"?unspecFuncMemptrEq@@
604 // X64: ({ i8*, i32, i32, i32 }* noundef %0, { i8*, i32, i32, i32 }* noundef %1)
607 bool unspecFuncMemptrNeq(void (Unspecified::*l)(), void (Unspecified::*r)()) {
608 return l != r;
609 // CHECK: define dso_local noundef zeroext i1 @"?unspecFuncMemptrNeq@@YA_NP8Unspecified@@AEXXZ0@Z"{{.*}} {
610 // CHECK: %[[lhs0:.*]] = extractvalue { i8*, i32, i32, i32 } %[[l:.*]], 0
611 // CHECK: %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[r:.*]], 0
612 // CHECK: %[[cmp0:.*]] = icmp ne i8* %[[lhs0]], %{{.*}}
613 // CHECK: %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[l]], 1
614 // CHECK: %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[r]], 1
615 // CHECK: %[[cmp1:.*]] = icmp ne i32
616 // CHECK: %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[l]], 2
617 // CHECK: %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[r]], 2
618 // CHECK: %[[cmp2:.*]] = icmp ne i32
619 // CHECK: %[[res12:.*]] = or i1 %[[cmp1]], %[[cmp2]]
620 // CHECK: %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[l]], 3
621 // CHECK: %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[r]], 3
622 // CHECK: %[[cmp3:.*]] = icmp ne i32
623 // CHECK: %[[res123:.*]] = or i1 %[[res12]], %[[cmp3]]
624 // CHECK: %[[iszero:.*]] = icmp ne i8* %[[lhs0]], null
625 // CHECK: %[[bits_or_null:.*]] = and i1 %[[res123]], %[[iszero]]
626 // CHECK: %{{.*}} = or i1 %[[bits_or_null]], %[[cmp0]]
627 // CHECK: ret i1 %{{.*}}
628 // CHECK: }
631 bool unspecDataMemptrEq(int Unspecified::*l, int Unspecified::*r) {
632 return l == r;
633 // CHECK: define dso_local noundef zeroext i1 @"?unspecDataMemptrEq@@YA_NPQUnspecified@@H0@Z"{{.*}} {
634 // CHECK: extractvalue { i32, i32, i32 } %{{.*}}, 0
635 // CHECK: extractvalue { i32, i32, i32 } %{{.*}}, 0
636 // CHECK: icmp eq i32
637 // CHECK: extractvalue { i32, i32, i32 } %{{.*}}, 1
638 // CHECK: extractvalue { i32, i32, i32 } %{{.*}}, 1
639 // CHECK: icmp eq i32
640 // CHECK: extractvalue { i32, i32, i32 } %{{.*}}, 2
641 // CHECK: extractvalue { i32, i32, i32 } %{{.*}}, 2
642 // CHECK: icmp eq i32
643 // CHECK: and i1
644 // CHECK: and i1
645 // CHECK: ret i1
646 // CHECK: }
648 // X64-LABEL: define dso_local noundef zeroext i1 @"?unspecDataMemptrEq@@
649 // X64: ({ i32, i32, i32 }* noundef %0, { i32, i32, i32 }* noundef %1)
652 void (Multiple::*convertB2FuncToMultiple(void (B2::*mp)()))() {
653 return mp;
654 // CHECK: define dso_local i64 @"?convertB2FuncToMultiple@@YAP8Multiple@@AEXXZP8B2@@AEXXZ@Z"{{.*}} {
655 // CHECK: store
656 // CHECK: %[[mp:.*]] = load i8*, i8** %{{.*}}, align 4
657 // CHECK: icmp ne i8* %[[mp]], null
658 // CHECK: br i1 %{{.*}} label %{{.*}}, label %{{.*}}
660 // memptr.convert: ; preds = %entry
661 // CHECK: insertvalue { i8*, i32 } undef, i8* %[[mp]], 0
662 // CHECK: insertvalue { i8*, i32 } %{{.*}}, i32 4, 1
663 // CHECK: br label
665 // memptr.converted: ; preds = %memptr.convert, %entry
666 // CHECK: phi { i8*, i32 } [ zeroinitializer, %{{.*}} ], [ {{.*}} ]
667 // CHECK: }
670 void (B2::*convertMultipleFuncToB2(void (Multiple::*mp)()))() {
671 // FIXME: cl emits warning C4407 on this code because of the representation
672 // change. We might want to do the same.
673 return static_cast<void (B2::*)()>(mp);
674 // FIXME: We should return i8* instead of i32 here. The ptrtoint cast prevents
675 // LLVM from optimizing away the branch. This is likely a bug in
676 // lib/CodeGen/TargetInfo.cpp with how we classify memptr types for returns.
678 // CHECK: define dso_local i32 @"?convertMultipleFuncToB2@@YAP8B2@@AEXXZP8Multiple@@AEXXZ@Z"{{.*}} {
679 // CHECK: store
680 // CHECK: %[[src:.*]] = load { i8*, i32 }, { i8*, i32 }* %{{.*}}, align 4
681 // CHECK: extractvalue { i8*, i32 } %[[src]], 0
682 // CHECK: icmp ne i8* %{{.*}}, null
683 // CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}
685 // memptr.convert: ; preds = %entry
686 // CHECK: %[[fp:.*]] = extractvalue { i8*, i32 } %[[src]], 0
687 // CHECK: br label
689 // memptr.converted: ; preds = %memptr.convert, %entry
690 // CHECK: phi i8* [ null, %{{.*}} ], [ %[[fp]], %{{.*}} ]
691 // CHECK: }
694 namespace Test1 {
696 struct A { int a; };
697 struct B { int b; };
698 struct C : virtual A { int c; };
699 struct D : B, C { int d; };
701 void (D::*convertCToD(void (C::*mp)()))() {
702 return mp;
703 // CHECK: define dso_local void @"?convertCToD@Test1@@YAP8D@1@AEXXZP8C@1@AEXXZ@Z"{{.*}} {
704 // CHECK: store
705 // CHECK: load { i8*, i32, i32 }, { i8*, i32, i32 }* %{{.*}}, align 4
706 // CHECK: extractvalue { i8*, i32, i32 } %{{.*}}, 0
707 // CHECK: icmp ne i8* %{{.*}}, null
708 // CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}
710 // memptr.convert: ; preds = %entry
711 // CHECK: extractvalue { i8*, i32, i32 } %{{.*}}, 0
712 // CHECK: %[[nvoff:.*]] = extractvalue { i8*, i32, i32 } %{{.*}}, 1
713 // CHECK: %[[vbidx:.*]] = extractvalue { i8*, i32, i32 } %{{.*}}, 2
714 // CHECK: %[[is_nvbase:.*]] = icmp eq i32 %[[vbidx]], 0
715 // CHECK: %[[nv_disp:.*]] = add nsw i32 %[[nvoff]], 4
716 // CHECK: %[[nv_adj:.*]] = select i1 %[[is_nvbase]], i32 %[[nv_disp]], i32 0
717 // CHECK: %[[dst_adj:.*]] = select i1 %[[is_nvbase]], i32 4, i32 0
718 // CHECK: %[[adj:.*]] = sub nsw i32 %[[nv_adj]], %[[dst_adj]]
719 // CHECK: insertvalue { i8*, i32, i32 } undef, i8* {{.*}}, 0
720 // CHECK: insertvalue { i8*, i32, i32 } {{.*}}, i32 %[[adj]], 1
721 // CHECK: insertvalue { i8*, i32, i32 } {{.*}}, i32 {{.*}}, 2
722 // CHECK: br label
724 // memptr.converted: ; preds = %memptr.convert, %entry
725 // CHECK: phi { i8*, i32, i32 } [ { i8* null, i32 0, i32 -1 }, {{.*}} ], [ {{.*}} ]
726 // CHECK: }
731 namespace Test2 {
732 // Test that we dynamically convert between different null reps.
734 struct A { int a; };
735 struct B : A { int b; };
736 struct C : A {
737 int c;
738 virtual void hasVfPtr();
741 int A::*reinterpret(int B::*mp) {
742 return reinterpret_cast<int A::*>(mp);
743 // CHECK: define dso_local i32 @"?reinterpret@Test2@@YAPQA@1@HPQB@1@H@Z"{{.*}} {
744 // CHECK-NOT: select
745 // CHECK: ret i32
746 // CHECK: }
749 int A::*reinterpret(int C::*mp) {
750 return reinterpret_cast<int A::*>(mp);
751 // CHECK: define dso_local i32 @"?reinterpret@Test2@@YAPQA@1@HPQC@1@H@Z"{{.*}} {
752 // CHECK: %[[mp:.*]] = load i32, i32*
753 // CHECK: %[[cmp:.*]] = icmp ne i32 %[[mp]], 0
754 // CHECK: select i1 %[[cmp]], i32 %[[mp]], i32 -1
755 // CHECK: }
760 namespace Test3 {
761 // Make sure we cast 'this' to i8* before using GEP.
763 struct A {
764 int a;
765 int b;
768 int *load_data(A *a, int A::*mp) {
769 return &(a->*mp);
770 // CHECK-LABEL: define dso_local noundef i32* @"?load_data@Test3@@YAPAHPAUA@1@PQ21@H@Z"{{.*}} {
771 // CHECK: %[[a:.*]] = load %"struct.Test3::A"*, %"struct.Test3::A"** %{{.*}}, align 4
772 // CHECK: %[[mp:.*]] = load i32, i32* %{{.*}}, align 4
773 // CHECK: %[[a_i8:.*]] = bitcast %"struct.Test3::A"* %[[a]] to i8*
774 // CHECK: getelementptr inbounds i8, i8* %[[a_i8]], i32 %[[mp]]
775 // CHECK: }
780 namespace Test4 {
782 struct A { virtual void f(); };
783 struct B { virtual void g(); };
784 struct C : A, B { virtual void g(); };
786 void (C::*getmp())() {
787 return &C::g;
789 // CHECK-LABEL: define dso_local i64 @"?getmp@Test4@@YAP8C@1@AEXXZXZ"()
790 // CHECK: store { i8*, i32 } { i8* bitcast (void (%"struct.Test4::C"*, ...)* @"??_9C@Test4@@$BA@AE" to i8*), i32 4 }, { i8*, i32 }* %{{.*}}
793 // CHECK-LABEL: define linkonce_odr x86_thiscallcc void @"??_9C@Test4@@$BA@AE"(%"struct.Test4::C"* noundef %this, ...) {{.*}} comdat
794 // CHECK-NOT: getelementptr
795 // CHECK: load void (%"struct.Test4::C"*, ...)**, void (%"struct.Test4::C"*, ...)*** %{{.*}}
796 // CHECK: getelementptr inbounds void (%"struct.Test4::C"*, ...)*, void (%"struct.Test4::C"*, ...)** %{{.*}}, i64 0
797 // CHECK-NOT: getelementptr
798 // CHECK: musttail call x86_thiscallcc void (%"struct.Test4::C"*, ...) %
802 namespace pr20007 {
803 struct A {
804 void f();
805 void f(int);
807 struct B : public A {};
808 void test() { void (B::*a)() = &B::f; }
809 // CHECK-LABEL: define dso_local void @"?test@pr20007@@YAXXZ"
810 // CHECK: store i8* bitcast (void (%"struct.pr20007::A"*)* @"?f@A@pr20007@@QAEXXZ" to i8*)
813 namespace pr20007_kw {
814 struct A {
815 void f();
816 void f(int);
818 struct __single_inheritance B;
819 struct B : public A {};
820 void test() { void (B::*a)() = &B::f; }
821 // CHECK-LABEL: define dso_local void @"?test@pr20007_kw@@YAXXZ"
822 // CHECK: store i8* bitcast (void (%"struct.pr20007_kw::A"*)* @"?f@A@pr20007_kw@@QAEXXZ" to i8*)
825 namespace pr20007_pragma {
826 struct A {
827 void f();
828 void f(int);
830 struct B : public A {};
831 void test() { (void)(void (B::*)()) &B::f; }
832 #pragma pointers_to_members(full_generality, virtual_inheritance)
833 static_assert(sizeof(int B::*) == 4, "");
834 static_assert(sizeof(int A::*) == 4, "");
835 #pragma pointers_to_members(best_case)
836 // CHECK-LABEL: define dso_local void @"?test@pr20007_pragma@@YAXXZ"
839 namespace pr20007_pragma2 {
840 struct A {
842 struct B : public A {
843 void f();
845 void test() { (void)&B::f; }
846 #pragma pointers_to_members(full_generality, virtual_inheritance)
847 static_assert(sizeof(int B::*) == 4, "");
848 static_assert(sizeof(int A::*) == 12, "");
849 #pragma pointers_to_members(best_case)
850 // CHECK-LABEL: define dso_local void @"?test@pr20007_pragma2@@YAXXZ"
853 namespace pr23823 {
854 struct Base { void Method(); };
855 struct Child : Base {};
856 void use(void (Child::*const &)());
857 void f() { use(&Child::Method); }
858 #pragma pointers_to_members(full_generality, virtual_inheritance)
859 static_assert(sizeof(int Base::*) == 4, "");
860 static_assert(sizeof(int Child::*) == 4, "");
861 #pragma pointers_to_members(best_case)
864 namespace pr19987 {
865 template <typename T>
866 struct S {
867 int T::*x;
870 struct U : S<U> {};
872 static_assert(sizeof(S<U>::x) == 12, "");
875 #else
876 struct __virtual_inheritance A;
877 #ifdef MEMFUN
878 int foo(A *a, int (A::*mp)()) {
879 return (a->*mp)(); // expected-error{{requires a complete class type}}
881 #else
882 int foo(A *a, int A::*mp) {
883 return a->*mp; // expected-error{{requires a complete class type}}
885 #endif
886 #endif
888 namespace pr23878 {
889 struct A { virtual void g(); };
890 struct B { virtual void f(); };
891 struct C : virtual B { void f(); };
892 struct D : A, C {};
894 typedef void (D::*DMemPtrTy)();
896 // CHECK-LABEL: define dso_local void @"?get_memptr@pr23878@@YAP8D@1@AEXXZXZ"
897 // CHECK: @"??_9C@pr23878@@$BA@AE" to i8*), i32 0, i32 4
898 DMemPtrTy get_memptr() { return &D::f; }
901 class C {};
903 typedef void (C::*f)();
905 class CA : public C {
906 public:
907 void OnHelp(void);
908 int OnHelp(int);
911 // CHECK-LABEL: foo_fun
912 void foo_fun() {
913 // CHECK: store i8* bitcast (void (%class.CA*)* @"?OnHelp@CA@@QAEXXZ" to i8*), i8**
914 f func = (f)&CA::OnHelp;
916 namespace PR24703 {
917 struct S;
919 void f(int S::*&p) {}
920 // CHECK-LABEL: define dso_local void @"?f@PR24703@@YAXAAPQS@1@H@Z"(
923 namespace ReferenceToMPTWithIncompleteClass {
924 struct S;
925 struct J;
926 struct K;
927 extern K *k;
929 // CHECK-LABEL: @"?f@ReferenceToMPTWithIncompleteClass@@YAIAAPQS@1@H@Z"(
930 // CHECK: ret i32 12
931 unsigned f(int S::*&p) { return sizeof p; }
933 // CHECK-LABEL: @"?g@ReferenceToMPTWithIncompleteClass@@YA_NAAPQJ@1@H0@Z"(
934 bool g(int J::*&p, int J::*&q) { return p == q; }
936 // CHECK-LABEL: @"?h@ReferenceToMPTWithIncompleteClass@@YAHAAPQK@1@H@Z"(
937 int h(int K::*&p) { return k->*p; }
940 namespace PMFInTemplateArgument {
941 template <class C, int (C::*M)(int)>
942 void JSMethod();
943 class A {
944 int printd(int);
945 void printd();
947 void A::printd() { JSMethod<A, &A::printd>(); }
948 // CHECK-LABEL: @"??$JSMethod@VA@PMFInTemplateArgument@@$1?printd@12@AAEHH@Z@PMFInTemplateArgument@@YAXXZ"(