xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/microsoft-abi-member-pointers.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -std=c++11 -Wno-uninitialized -fno-rtti -emit-llvm %s -o - -triple=i386-pc-win32 -fms-extensions | FileCheck %s
2*0a6a1f1dSLionel Sambuc // 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*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -std=c++11 -Wno-uninitialized -fno-rtti -emit-llvm %s -o - -triple=i386-pc-win32 -DINCOMPLETE_VIRTUAL -fms-extensions -verify
4*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -std=c++11 -Wno-uninitialized -fno-rtti -emit-llvm %s -o - -triple=i386-pc-win32 -DINCOMPLETE_VIRTUAL -DMEMFUN -fms-extensions -verify
5f4a2713aSLionel Sambuc 
6*0a6a1f1dSLionel Sambuc namespace PR20947 {
7*0a6a1f1dSLionel Sambuc struct A;
8*0a6a1f1dSLionel Sambuc int A::**a = nullptr;
9*0a6a1f1dSLionel Sambuc // CHECK: %[[opaque0:.*]] = type opaque
10*0a6a1f1dSLionel Sambuc // CHECK: %[[opaque1:.*]] = type opaque
11*0a6a1f1dSLionel Sambuc // CHECK: @"\01?a@PR20947@@3PAPQA@1@HA" = global %[[opaque0]]* null, align 4
12*0a6a1f1dSLionel Sambuc 
13*0a6a1f1dSLionel Sambuc struct B;
14*0a6a1f1dSLionel Sambuc int B::*&b = b;
15*0a6a1f1dSLionel Sambuc // CHECK: @"\01?b@PR20947@@3AAPQB@1@HA" = global %[[opaque1]]* null, align 4
16*0a6a1f1dSLionel Sambuc }
17*0a6a1f1dSLionel Sambuc 
18*0a6a1f1dSLionel Sambuc namespace PR20017 {
19*0a6a1f1dSLionel Sambuc template <typename T>
20*0a6a1f1dSLionel Sambuc struct A {
m_fn1PR20017::A21*0a6a1f1dSLionel Sambuc   int T::*m_fn1() { return nullptr; }
22*0a6a1f1dSLionel Sambuc };
23*0a6a1f1dSLionel Sambuc struct B;
24*0a6a1f1dSLionel Sambuc auto a = &A<B>::m_fn1;
25*0a6a1f1dSLionel Sambuc // CHECK-DAG: @"\01?a@PR20017@@3P8?$A@UB@PR20017@@@1@AEPQB@1@HXZQ21@" = global i8* bitcast ({ i32, i32, i32 } ({{.*}}*)* @"\01?m_fn1@?$A@UB@PR20017@@@PR20017@@QAEPQB@2@HXZ" to i8*), align 4
26*0a6a1f1dSLionel Sambuc }
27*0a6a1f1dSLionel Sambuc 
28*0a6a1f1dSLionel Sambuc #ifndef INCOMPLETE_VIRTUAL
29f4a2713aSLionel Sambuc struct B1 {
30f4a2713aSLionel Sambuc   void foo();
31f4a2713aSLionel Sambuc   int b;
32f4a2713aSLionel Sambuc };
33f4a2713aSLionel Sambuc struct B2 {
34f4a2713aSLionel Sambuc   int b2;
35f4a2713aSLionel Sambuc   void foo();
36f4a2713aSLionel Sambuc };
37f4a2713aSLionel Sambuc struct Single : B1 {
38f4a2713aSLionel Sambuc   void foo();
39f4a2713aSLionel Sambuc };
40f4a2713aSLionel Sambuc struct Multiple : B1, B2 {
41f4a2713aSLionel Sambuc   int m;
42f4a2713aSLionel Sambuc   void foo();
43f4a2713aSLionel Sambuc };
44f4a2713aSLionel Sambuc struct Virtual : virtual B1 {
45f4a2713aSLionel Sambuc   int v;
46f4a2713aSLionel Sambuc   void foo();
47f4a2713aSLionel Sambuc };
48f4a2713aSLionel Sambuc 
49f4a2713aSLionel Sambuc struct POD {
50f4a2713aSLionel Sambuc   int a;
51f4a2713aSLionel Sambuc   int b;
52f4a2713aSLionel Sambuc };
53f4a2713aSLionel Sambuc 
54f4a2713aSLionel Sambuc struct Polymorphic {
55f4a2713aSLionel Sambuc   virtual void myVirtual();
56f4a2713aSLionel Sambuc   int a;
57f4a2713aSLionel Sambuc   int b;
58f4a2713aSLionel Sambuc };
59f4a2713aSLionel Sambuc 
60f4a2713aSLionel Sambuc // This class uses the virtual inheritance model, yet its vbptr offset is not 0.
61f4a2713aSLionel Sambuc // We still use zero for the null field offset, despite it being a valid field
62f4a2713aSLionel Sambuc // offset.
63f4a2713aSLionel Sambuc struct NonZeroVBPtr : POD, Virtual {
64f4a2713aSLionel Sambuc   int n;
65f4a2713aSLionel Sambuc   void foo();
66f4a2713aSLionel Sambuc };
67f4a2713aSLionel Sambuc 
68f4a2713aSLionel Sambuc struct Unspecified;
69f4a2713aSLionel Sambuc struct UnspecSingle;
70f4a2713aSLionel Sambuc 
71f4a2713aSLionel Sambuc // Check that we can lower the LLVM types and get the null initializers right.
72f4a2713aSLionel Sambuc int Single     ::*s_d_memptr;
73f4a2713aSLionel Sambuc int Polymorphic::*p_d_memptr;
74f4a2713aSLionel Sambuc int Multiple   ::*m_d_memptr;
75f4a2713aSLionel Sambuc int Virtual    ::*v_d_memptr;
76f4a2713aSLionel Sambuc int NonZeroVBPtr::*n_d_memptr;
77f4a2713aSLionel Sambuc int Unspecified::*u_d_memptr;
78f4a2713aSLionel Sambuc int UnspecSingle::*us_d_memptr;
79f4a2713aSLionel Sambuc // CHECK: @"\01?s_d_memptr@@3PQSingle@@HQ1@" = global i32 -1, align 4
80f4a2713aSLionel Sambuc // CHECK: @"\01?p_d_memptr@@3PQPolymorphic@@HQ1@" = global i32 0, align 4
81f4a2713aSLionel Sambuc // CHECK: @"\01?m_d_memptr@@3PQMultiple@@HQ1@" = global i32 -1, align 4
82f4a2713aSLionel Sambuc // CHECK: @"\01?v_d_memptr@@3PQVirtual@@HQ1@" = global { i32, i32 }
83*0a6a1f1dSLionel Sambuc // CHECK:   { i32 0, i32 -1 }, align 8
84f4a2713aSLionel Sambuc // CHECK: @"\01?n_d_memptr@@3PQNonZeroVBPtr@@HQ1@" = global { i32, i32 }
85*0a6a1f1dSLionel Sambuc // CHECK:   { i32 0, i32 -1 }, align 8
86f4a2713aSLionel Sambuc // CHECK: @"\01?u_d_memptr@@3PQUnspecified@@HQ1@" = global { i32, i32, i32 }
87*0a6a1f1dSLionel Sambuc // CHECK:   { i32 0, i32 0, i32 -1 }, align 8
88f4a2713aSLionel Sambuc // CHECK: @"\01?us_d_memptr@@3PQUnspecSingle@@HQ1@" = global { i32, i32, i32 }
89*0a6a1f1dSLionel Sambuc // CHECK:   { i32 0, i32 0, i32 -1 }, align 8
90f4a2713aSLionel Sambuc 
91f4a2713aSLionel Sambuc void (Single  ::*s_f_memptr)();
92f4a2713aSLionel Sambuc void (Multiple::*m_f_memptr)();
93f4a2713aSLionel Sambuc void (Virtual ::*v_f_memptr)();
94f4a2713aSLionel Sambuc // CHECK: @"\01?s_f_memptr@@3P8Single@@AEXXZQ1@" = global i8* null, align 4
95*0a6a1f1dSLionel Sambuc // CHECK: @"\01?m_f_memptr@@3P8Multiple@@AEXXZQ1@" = global { i8*, i32 } zeroinitializer, align 8
96*0a6a1f1dSLionel Sambuc // CHECK: @"\01?v_f_memptr@@3P8Virtual@@AEXXZQ1@" = global { i8*, i32, i32 } zeroinitializer, align 8
97f4a2713aSLionel Sambuc 
98f4a2713aSLionel Sambuc // We can define Unspecified after locking in the inheritance model.
99f4a2713aSLionel Sambuc struct Unspecified : Multiple, Virtual {
100f4a2713aSLionel Sambuc   void foo();
101f4a2713aSLionel Sambuc   int u;
102f4a2713aSLionel Sambuc };
103f4a2713aSLionel Sambuc 
104f4a2713aSLionel Sambuc struct UnspecSingle {
105f4a2713aSLionel Sambuc   void foo();
106f4a2713aSLionel Sambuc };
107f4a2713aSLionel Sambuc 
108f4a2713aSLionel Sambuc // Test memptr emission in a constant expression.
109f4a2713aSLionel Sambuc namespace Const {
110f4a2713aSLionel Sambuc void (Single     ::*s_f_mp)() = &Single::foo;
111f4a2713aSLionel Sambuc void (Multiple   ::*m_f_mp)() = &B2::foo;
112f4a2713aSLionel Sambuc void (Virtual    ::*v_f_mp)() = &Virtual::foo;
113f4a2713aSLionel Sambuc void (Unspecified::*u_f_mp)() = &Unspecified::foo;
114f4a2713aSLionel Sambuc void (UnspecSingle::*us_f_mp)() = &UnspecSingle::foo;
115f4a2713aSLionel Sambuc // CHECK: @"\01?s_f_mp@Const@@3P8Single@@AEXXZQ2@" =
116f4a2713aSLionel Sambuc // CHECK:   global i8* bitcast ({{.*}} @"\01?foo@Single@@QAEXXZ" to i8*), align 4
117f4a2713aSLionel Sambuc // CHECK: @"\01?m_f_mp@Const@@3P8Multiple@@AEXXZQ2@" =
118*0a6a1f1dSLionel Sambuc // CHECK:   global { i8*, i32 } { i8* bitcast ({{.*}} @"\01?foo@B2@@QAEXXZ" to i8*), i32 4 }, align 8
119f4a2713aSLionel Sambuc // CHECK: @"\01?v_f_mp@Const@@3P8Virtual@@AEXXZQ2@" =
120*0a6a1f1dSLionel Sambuc // CHECK:   global { i8*, i32, i32 } { i8* bitcast ({{.*}} @"\01?foo@Virtual@@QAEXXZ" to i8*), i32 0, i32 0 }, align 8
121f4a2713aSLionel Sambuc // CHECK: @"\01?u_f_mp@Const@@3P8Unspecified@@AEXXZQ2@" =
122*0a6a1f1dSLionel Sambuc // CHECK:   global { i8*, i32, i32, i32 } { i8* bitcast ({{.*}} @"\01?foo@Unspecified@@QAEXXZ" to i8*), i32 0, i32 12, i32 0 }, align 8
123f4a2713aSLionel Sambuc // CHECK: @"\01?us_f_mp@Const@@3P8UnspecSingle@@AEXXZQ2@" =
124*0a6a1f1dSLionel Sambuc // CHECK:   global { i8*, i32, i32, i32 } { i8* bitcast ({{.*}} @"\01?foo@UnspecSingle@@QAEXXZ" to i8*), i32 0, i32 0, i32 0 }, align 8
125f4a2713aSLionel Sambuc }
126f4a2713aSLionel Sambuc 
127f4a2713aSLionel Sambuc namespace CastParam {
128f4a2713aSLionel Sambuc // This exercises ConstExprEmitter instead of ValueDecl::evaluateValue.  The
129f4a2713aSLionel Sambuc // extra reinterpret_cast for the parameter type requires more careful folding.
130f4a2713aSLionel Sambuc // FIXME: Or does it?  If reinterpret_casts are no-ops, we should be able to
131f4a2713aSLionel Sambuc // strip them in evaluateValue() and just proceed as normal with an APValue.
132f4a2713aSLionel Sambuc struct A {
133f4a2713aSLionel Sambuc   int a;
134f4a2713aSLionel Sambuc   void foo(A *p);
135f4a2713aSLionel Sambuc };
136f4a2713aSLionel Sambuc struct B { int b; };
137f4a2713aSLionel Sambuc struct C : B, A { int c; };
138f4a2713aSLionel Sambuc 
139f4a2713aSLionel Sambuc void (A::*ptr1)(void *) = (void (A::*)(void *)) &A::foo;
140f4a2713aSLionel Sambuc // CHECK: @"\01?ptr1@CastParam@@3P8A@1@AEXPAX@ZQ21@" =
141f4a2713aSLionel Sambuc // CHECK:   global i8* bitcast (void ({{.*}})* @"\01?foo@A@CastParam@@QAEXPAU12@@Z" to i8*), align 4
142f4a2713aSLionel Sambuc 
143f4a2713aSLionel Sambuc // Try a reinterpret_cast followed by a memptr conversion.
144f4a2713aSLionel Sambuc void (C::*ptr2)(void *) = (void (C::*)(void *)) (void (A::*)(void *)) &A::foo;
145f4a2713aSLionel Sambuc // CHECK: @"\01?ptr2@CastParam@@3P8C@1@AEXPAX@ZQ21@" =
146*0a6a1f1dSLionel Sambuc // CHECK:   global { i8*, i32 } { i8* bitcast (void ({{.*}})* @"\01?foo@A@CastParam@@QAEXPAU12@@Z" to i8*), i32 4 }, align 8
147f4a2713aSLionel Sambuc 
148f4a2713aSLionel Sambuc void (C::*ptr3)(void *) = (void (C::*)(void *)) (void (A::*)(void *)) (void (A::*)(A *)) 0;
149f4a2713aSLionel Sambuc // CHECK: @"\01?ptr3@CastParam@@3P8C@1@AEXPAX@ZQ21@" =
150*0a6a1f1dSLionel Sambuc // CHECK:   global { i8*, i32 } zeroinitializer, align 8
151f4a2713aSLionel Sambuc 
152f4a2713aSLionel Sambuc struct D : C {
153f4a2713aSLionel Sambuc   virtual void isPolymorphic();
154f4a2713aSLionel Sambuc   int d;
155f4a2713aSLionel Sambuc };
156f4a2713aSLionel Sambuc 
157f4a2713aSLionel Sambuc // Try a cast that changes the inheritance model.  Null for D is 0, but null for
158f4a2713aSLionel Sambuc // C is -1.  We need the cast to long in order to hit the non-APValue path.
159f4a2713aSLionel Sambuc int C::*ptr4 = (int C::*) (int D::*) (long D::*) 0;
160f4a2713aSLionel Sambuc // CHECK: @"\01?ptr4@CastParam@@3PQC@1@HQ21@" = global i32 -1, align 4
161f4a2713aSLionel Sambuc 
162f4a2713aSLionel Sambuc // MSVC rejects this but we accept it.
163f4a2713aSLionel Sambuc int C::*ptr5 = (int C::*) (long D::*) 0;
164f4a2713aSLionel Sambuc // CHECK: @"\01?ptr5@CastParam@@3PQC@1@HQ21@" = global i32 -1, align 4
165f4a2713aSLionel Sambuc }
166f4a2713aSLionel Sambuc 
167f4a2713aSLionel Sambuc struct UnspecWithVBPtr;
168f4a2713aSLionel Sambuc int UnspecWithVBPtr::*forceUnspecWithVBPtr;
169f4a2713aSLionel Sambuc struct UnspecWithVBPtr : B1, virtual B2 {
170f4a2713aSLionel Sambuc   int u;
171f4a2713aSLionel Sambuc   void foo();
172f4a2713aSLionel Sambuc };
173f4a2713aSLionel Sambuc 
174f4a2713aSLionel Sambuc // Test emitting non-virtual member pointers in a non-constexpr setting.
EmitNonVirtualMemberPointers()175f4a2713aSLionel Sambuc void EmitNonVirtualMemberPointers() {
176f4a2713aSLionel Sambuc   void (Single     ::*s_f_memptr)() = &Single::foo;
177f4a2713aSLionel Sambuc   void (Multiple   ::*m_f_memptr)() = &Multiple::foo;
178f4a2713aSLionel Sambuc   void (Virtual    ::*v_f_memptr)() = &Virtual::foo;
179f4a2713aSLionel Sambuc   void (Unspecified::*u_f_memptr)() = &Unspecified::foo;
180f4a2713aSLionel Sambuc   void (UnspecWithVBPtr::*u2_f_memptr)() = &UnspecWithVBPtr::foo;
181f4a2713aSLionel Sambuc // CHECK: define void @"\01?EmitNonVirtualMemberPointers@@YAXXZ"() {{.*}} {
182f4a2713aSLionel Sambuc // CHECK:   alloca i8*, align 4
183*0a6a1f1dSLionel Sambuc // CHECK:   alloca { i8*, i32 }, align 8
184*0a6a1f1dSLionel Sambuc // CHECK:   alloca { i8*, i32, i32 }, align 8
185*0a6a1f1dSLionel Sambuc // CHECK:   alloca { i8*, i32, i32, i32 }, align 8
186f4a2713aSLionel Sambuc // CHECK:   store i8* bitcast (void (%{{.*}}*)* @"\01?foo@Single@@QAEXXZ" to i8*), i8** %{{.*}}, align 4
187f4a2713aSLionel Sambuc // CHECK:   store { i8*, i32 }
188f4a2713aSLionel Sambuc // CHECK:     { i8* bitcast (void (%{{.*}}*)* @"\01?foo@Multiple@@QAEXXZ" to i8*), i32 0 },
189*0a6a1f1dSLionel Sambuc // CHECK:     { i8*, i32 }* %{{.*}}, align 8
190f4a2713aSLionel Sambuc // CHECK:   store { i8*, i32, i32 }
191f4a2713aSLionel Sambuc // CHECK:     { i8* bitcast (void (%{{.*}}*)* @"\01?foo@Virtual@@QAEXXZ" to i8*), i32 0, i32 0 },
192*0a6a1f1dSLionel Sambuc // CHECK:     { i8*, i32, i32 }* %{{.*}}, align 8
193f4a2713aSLionel Sambuc // CHECK:   store { i8*, i32, i32, i32 }
194f4a2713aSLionel Sambuc // CHECK:     { i8* bitcast (void (%{{.*}}*)* @"\01?foo@Unspecified@@QAEXXZ" to i8*), i32 0, i32 12, i32 0 },
195*0a6a1f1dSLionel Sambuc // CHECK:     { i8*, i32, i32, i32 }* %{{.*}}, align 8
196f4a2713aSLionel Sambuc // CHECK:   store { i8*, i32, i32, i32 }
197f4a2713aSLionel Sambuc // CHECK:     { i8* bitcast (void (%{{.*}}*)* @"\01?foo@UnspecWithVBPtr@@QAEXXZ" to i8*),
198f4a2713aSLionel Sambuc // CHECK:       i32 0, i32 4, i32 0 },
199*0a6a1f1dSLionel Sambuc // CHECK:     { i8*, i32, i32, i32 }* %{{.*}}, align 8
200f4a2713aSLionel Sambuc // CHECK:   ret void
201f4a2713aSLionel Sambuc // CHECK: }
202f4a2713aSLionel Sambuc }
203f4a2713aSLionel Sambuc 
podMemPtrs()204f4a2713aSLionel Sambuc void podMemPtrs() {
205f4a2713aSLionel Sambuc   int POD::*memptr;
206f4a2713aSLionel Sambuc   memptr = &POD::a;
207f4a2713aSLionel Sambuc   memptr = &POD::b;
208f4a2713aSLionel Sambuc   if (memptr)
209f4a2713aSLionel Sambuc     memptr = 0;
210f4a2713aSLionel Sambuc // Check that member pointers use the right offsets and that null is -1.
211f4a2713aSLionel Sambuc // CHECK:      define void @"\01?podMemPtrs@@YAXXZ"() {{.*}} {
212f4a2713aSLionel Sambuc // CHECK:        %[[memptr:.*]] = alloca i32, align 4
213f4a2713aSLionel Sambuc // CHECK-NEXT:   store i32 0, i32* %[[memptr]], align 4
214f4a2713aSLionel Sambuc // CHECK-NEXT:   store i32 4, i32* %[[memptr]], align 4
215f4a2713aSLionel Sambuc // CHECK-NEXT:   %[[memptr_val:.*]] = load i32* %[[memptr]], align 4
216f4a2713aSLionel Sambuc // CHECK-NEXT:   %{{.*}} = icmp ne i32 %[[memptr_val]], -1
217f4a2713aSLionel Sambuc // CHECK-NEXT:   br i1 %{{.*}}, label %{{.*}}, label %{{.*}}
218f4a2713aSLionel Sambuc // CHECK:        store i32 -1, i32* %[[memptr]], align 4
219f4a2713aSLionel Sambuc // CHECK:        ret void
220f4a2713aSLionel Sambuc // CHECK:      }
221f4a2713aSLionel Sambuc }
222f4a2713aSLionel Sambuc 
polymorphicMemPtrs()223f4a2713aSLionel Sambuc void polymorphicMemPtrs() {
224f4a2713aSLionel Sambuc   int Polymorphic::*memptr;
225f4a2713aSLionel Sambuc   memptr = &Polymorphic::a;
226f4a2713aSLionel Sambuc   memptr = &Polymorphic::b;
227f4a2713aSLionel Sambuc   if (memptr)
228f4a2713aSLionel Sambuc     memptr = 0;
229f4a2713aSLionel Sambuc // Member pointers for polymorphic classes include the vtable slot in their
230f4a2713aSLionel Sambuc // offset and use 0 to represent null.
231f4a2713aSLionel Sambuc // CHECK:      define void @"\01?polymorphicMemPtrs@@YAXXZ"() {{.*}} {
232f4a2713aSLionel Sambuc // CHECK:        %[[memptr:.*]] = alloca i32, align 4
233f4a2713aSLionel Sambuc // CHECK-NEXT:   store i32 4, i32* %[[memptr]], align 4
234f4a2713aSLionel Sambuc // CHECK-NEXT:   store i32 8, i32* %[[memptr]], align 4
235f4a2713aSLionel Sambuc // CHECK-NEXT:   %[[memptr_val:.*]] = load i32* %[[memptr]], align 4
236f4a2713aSLionel Sambuc // CHECK-NEXT:   %{{.*}} = icmp ne i32 %[[memptr_val]], 0
237f4a2713aSLionel Sambuc // CHECK-NEXT:   br i1 %{{.*}}, label %{{.*}}, label %{{.*}}
238f4a2713aSLionel Sambuc // CHECK:        store i32 0, i32* %[[memptr]], align 4
239f4a2713aSLionel Sambuc // CHECK:        ret void
240f4a2713aSLionel Sambuc // CHECK:      }
241f4a2713aSLionel Sambuc }
242f4a2713aSLionel Sambuc 
nullTestDataUnspecified(int Unspecified::* mp)243f4a2713aSLionel Sambuc bool nullTestDataUnspecified(int Unspecified::*mp) {
244f4a2713aSLionel Sambuc   return mp;
245f4a2713aSLionel Sambuc // CHECK: define zeroext i1 @"\01?nullTestDataUnspecified@@YA_NPQUnspecified@@H@Z"{{.*}} {
246*0a6a1f1dSLionel Sambuc // CHECK:   %{{.*}} = load { i32, i32, i32 }* %{{.*}}, align 8
247*0a6a1f1dSLionel Sambuc // CHECK:   store { i32, i32, i32 } {{.*}} align 8
248*0a6a1f1dSLionel Sambuc // CHECK:   %[[mp:.*]] = load { i32, i32, i32 }* %{{.*}}, align 8
249f4a2713aSLionel Sambuc // CHECK:   %[[mp0:.*]] = extractvalue { i32, i32, i32 } %[[mp]], 0
250f4a2713aSLionel Sambuc // CHECK:   %[[cmp0:.*]] = icmp ne i32 %[[mp0]], 0
251f4a2713aSLionel Sambuc // CHECK:   %[[mp1:.*]] = extractvalue { i32, i32, i32 } %[[mp]], 1
252f4a2713aSLionel Sambuc // CHECK:   %[[cmp1:.*]] = icmp ne i32 %[[mp1]], 0
253*0a6a1f1dSLionel Sambuc // CHECK:   %[[and0:.*]] = or i1 %[[cmp0]], %[[cmp1]]
254f4a2713aSLionel Sambuc // CHECK:   %[[mp2:.*]] = extractvalue { i32, i32, i32 } %[[mp]], 2
255f4a2713aSLionel Sambuc // CHECK:   %[[cmp2:.*]] = icmp ne i32 %[[mp2]], -1
256*0a6a1f1dSLionel Sambuc // CHECK:   %[[and1:.*]] = or i1 %[[and0]], %[[cmp2]]
257f4a2713aSLionel Sambuc // CHECK:   ret i1 %[[and1]]
258f4a2713aSLionel Sambuc // CHECK: }
259*0a6a1f1dSLionel Sambuc 
260*0a6a1f1dSLionel Sambuc // Pass this large type indirectly.
261*0a6a1f1dSLionel Sambuc // X64-LABEL: define zeroext i1 @"\01?nullTestDataUnspecified@@
262*0a6a1f1dSLionel Sambuc // X64:             ({ i32, i32, i32 }*)
263f4a2713aSLionel Sambuc }
264f4a2713aSLionel Sambuc 
nullTestFunctionUnspecified(void (Unspecified::* mp)())265f4a2713aSLionel Sambuc bool nullTestFunctionUnspecified(void (Unspecified::*mp)()) {
266f4a2713aSLionel Sambuc   return mp;
267f4a2713aSLionel Sambuc // CHECK: define zeroext i1 @"\01?nullTestFunctionUnspecified@@YA_NP8Unspecified@@AEXXZ@Z"{{.*}} {
268*0a6a1f1dSLionel Sambuc // CHECK:   %{{.*}} = load { i8*, i32, i32, i32 }* %{{.*}}, align 8
269*0a6a1f1dSLionel Sambuc // CHECK:   store { i8*, i32, i32, i32 } {{.*}} align 8
270*0a6a1f1dSLionel Sambuc // CHECK:   %[[mp:.*]] = load { i8*, i32, i32, i32 }* %{{.*}}, align 8
271f4a2713aSLionel Sambuc // CHECK:   %[[mp0:.*]] = extractvalue { i8*, i32, i32, i32 } %[[mp]], 0
272f4a2713aSLionel Sambuc // CHECK:   %[[cmp0:.*]] = icmp ne i8* %[[mp0]], null
273f4a2713aSLionel Sambuc // CHECK:   ret i1 %[[cmp0]]
274f4a2713aSLionel Sambuc // CHECK: }
275f4a2713aSLionel Sambuc }
276f4a2713aSLionel Sambuc 
loadDataMemberPointerVirtual(Virtual * o,int Virtual::* memptr)277f4a2713aSLionel Sambuc int loadDataMemberPointerVirtual(Virtual *o, int Virtual::*memptr) {
278f4a2713aSLionel Sambuc   return o->*memptr;
279f4a2713aSLionel Sambuc // Test that we can unpack this aggregate member pointer and load the member
280f4a2713aSLionel Sambuc // data pointer.
281f4a2713aSLionel Sambuc // CHECK: define i32 @"\01?loadDataMemberPointerVirtual@@YAHPAUVirtual@@PQ1@H@Z"{{.*}} {
282f4a2713aSLionel Sambuc // CHECK:   %[[o:.*]] = load %{{.*}}** %{{.*}}, align 4
283*0a6a1f1dSLionel Sambuc // CHECK:   %[[memptr:.*]] = load { i32, i32 }* %{{.*}}, align 8
284f4a2713aSLionel Sambuc // CHECK:   %[[memptr0:.*]] = extractvalue { i32, i32 } %[[memptr:.*]], 0
285f4a2713aSLionel Sambuc // CHECK:   %[[memptr1:.*]] = extractvalue { i32, i32 } %[[memptr:.*]], 1
286f4a2713aSLionel Sambuc // CHECK:   %[[v6:.*]] = bitcast %{{.*}}* %[[o]] to i8*
287f4a2713aSLionel Sambuc // CHECK:   %[[vbptr:.*]] = getelementptr inbounds i8* %[[v6]], i32 0
288*0a6a1f1dSLionel Sambuc // CHECK:   %[[vbptr_a:.*]] = bitcast i8* %[[vbptr]] to i32**
289*0a6a1f1dSLionel Sambuc // CHECK:   %[[vbtable:.*]] = load i32** %[[vbptr_a:.*]]
290*0a6a1f1dSLionel Sambuc // CHECK:   %[[memptr1_shr:.*]] = ashr exact i32 %[[memptr1]], 2
291*0a6a1f1dSLionel Sambuc // CHECK:   %[[v7:.*]] = getelementptr inbounds i32* %[[vbtable]], i32 %[[memptr1_shr]]
292*0a6a1f1dSLionel Sambuc // CHECK:   %[[vbase_offs:.*]] = load i32* %[[v7]]
293f4a2713aSLionel Sambuc // CHECK:   %[[v10:.*]] = getelementptr inbounds i8* %[[vbptr]], i32 %[[vbase_offs]]
294f4a2713aSLionel Sambuc // CHECK:   %[[offset:.*]] = getelementptr inbounds i8* %[[v10]], i32 %[[memptr0]]
295f4a2713aSLionel Sambuc // CHECK:   %[[v11:.*]] = bitcast i8* %[[offset]] to i32*
296f4a2713aSLionel Sambuc // CHECK:   %[[v12:.*]] = load i32* %[[v11]]
297f4a2713aSLionel Sambuc // CHECK:   ret i32 %[[v12]]
298f4a2713aSLionel Sambuc // CHECK: }
299*0a6a1f1dSLionel Sambuc 
300*0a6a1f1dSLionel Sambuc // A two-field data memptr on x64 gets coerced to i64 and is passed in a
301*0a6a1f1dSLionel Sambuc // register or memory.
302*0a6a1f1dSLionel Sambuc // X64-LABEL: define i32 @"\01?loadDataMemberPointerVirtual@@YAHPEAUVirtual@@PEQ1@H@Z"
303*0a6a1f1dSLionel Sambuc // X64:             (%struct.Virtual* %o, i64 %memptr.coerce)
304f4a2713aSLionel Sambuc }
305f4a2713aSLionel Sambuc 
loadDataMemberPointerUnspecified(Unspecified * o,int Unspecified::* memptr)306f4a2713aSLionel Sambuc int loadDataMemberPointerUnspecified(Unspecified *o, int Unspecified::*memptr) {
307f4a2713aSLionel Sambuc   return o->*memptr;
308f4a2713aSLionel Sambuc // Test that we can unpack this aggregate member pointer and load the member
309f4a2713aSLionel Sambuc // data pointer.
310f4a2713aSLionel Sambuc // CHECK: define i32 @"\01?loadDataMemberPointerUnspecified@@YAHPAUUnspecified@@PQ1@H@Z"{{.*}} {
311f4a2713aSLionel Sambuc // CHECK:   %[[o:.*]] = load %{{.*}}** %{{.*}}, align 4
312*0a6a1f1dSLionel Sambuc // CHECK:   %[[memptr:.*]] = load { i32, i32, i32 }* %{{.*}}, align 8
313f4a2713aSLionel Sambuc // CHECK:   %[[memptr0:.*]] = extractvalue { i32, i32, i32 } %[[memptr:.*]], 0
314f4a2713aSLionel Sambuc // CHECK:   %[[memptr1:.*]] = extractvalue { i32, i32, i32 } %[[memptr:.*]], 1
315f4a2713aSLionel Sambuc // CHECK:   %[[memptr2:.*]] = extractvalue { i32, i32, i32 } %[[memptr:.*]], 2
316f4a2713aSLionel Sambuc // CHECK:   %[[base:.*]] = bitcast %{{.*}}* %[[o]] to i8*
317f4a2713aSLionel Sambuc // CHECK:   %[[is_vbase:.*]] = icmp ne i32 %[[memptr2]], 0
318f4a2713aSLionel Sambuc // CHECK:   br i1 %[[is_vbase]], label %[[vadjust:.*]], label %[[skip:.*]]
319f4a2713aSLionel Sambuc //
320f4a2713aSLionel Sambuc // CHECK: [[vadjust]]
321f4a2713aSLionel Sambuc // CHECK:   %[[vbptr:.*]] = getelementptr inbounds i8* %[[base]], i32 %[[memptr1]]
322*0a6a1f1dSLionel Sambuc // CHECK:   %[[vbptr_a:.*]] = bitcast i8* %[[vbptr]] to i32**
323*0a6a1f1dSLionel Sambuc // CHECK:   %[[vbtable:.*]] = load i32** %[[vbptr_a:.*]]
324*0a6a1f1dSLionel Sambuc // CHECK:   %[[memptr2_shr:.*]] = ashr exact i32 %[[memptr2]], 2
325*0a6a1f1dSLionel Sambuc // CHECK:   %[[v7:.*]] = getelementptr inbounds i32* %[[vbtable]], i32 %[[memptr2_shr]]
326*0a6a1f1dSLionel Sambuc // CHECK:   %[[vbase_offs:.*]] = load i32* %[[v7]]
327f4a2713aSLionel Sambuc // CHECK:   %[[base_adj:.*]] = getelementptr inbounds i8* %[[vbptr]], i32 %[[vbase_offs]]
328f4a2713aSLionel Sambuc //
329f4a2713aSLionel Sambuc // CHECK: [[skip]]
330f4a2713aSLionel Sambuc // CHECK:   %[[new_base:.*]] = phi i8* [ %[[base]], %{{.*}} ], [ %[[base_adj]], %[[vadjust]] ]
331f4a2713aSLionel Sambuc // CHECK:   %[[offset:.*]] = getelementptr inbounds i8* %[[new_base]], i32 %[[memptr0]]
332f4a2713aSLionel Sambuc // CHECK:   %[[v11:.*]] = bitcast i8* %[[offset]] to i32*
333f4a2713aSLionel Sambuc // CHECK:   %[[v12:.*]] = load i32* %[[v11]]
334f4a2713aSLionel Sambuc // CHECK:   ret i32 %[[v12]]
335f4a2713aSLionel Sambuc // CHECK: }
336f4a2713aSLionel Sambuc }
337f4a2713aSLionel Sambuc 
callMemberPointerSingle(Single * o,void (Single::* memptr)())338f4a2713aSLionel Sambuc void callMemberPointerSingle(Single *o, void (Single::*memptr)()) {
339f4a2713aSLionel Sambuc   (o->*memptr)();
340f4a2713aSLionel Sambuc // Just look for an indirect thiscall.
341f4a2713aSLionel Sambuc // CHECK: define void @"\01?callMemberPointerSingle@@{{.*}} {{.*}} {
342f4a2713aSLionel Sambuc // CHECK:   call x86_thiscallcc void %{{.*}}(%{{.*}} %{{.*}})
343f4a2713aSLionel Sambuc // CHECK:   ret void
344f4a2713aSLionel Sambuc // CHECK: }
345*0a6a1f1dSLionel Sambuc 
346*0a6a1f1dSLionel Sambuc // X64-LABEL: define void @"\01?callMemberPointerSingle@@
347*0a6a1f1dSLionel Sambuc // X64:           (%struct.Single* %o, i8* %memptr)
348*0a6a1f1dSLionel Sambuc // X64:   bitcast i8* %{{[^ ]*}} to void (%struct.Single*)*
349*0a6a1f1dSLionel Sambuc // X64:   ret void
350f4a2713aSLionel Sambuc }
351f4a2713aSLionel Sambuc 
callMemberPointerMultiple(Multiple * o,void (Multiple::* memptr)())352f4a2713aSLionel Sambuc void callMemberPointerMultiple(Multiple *o, void (Multiple::*memptr)()) {
353f4a2713aSLionel Sambuc   (o->*memptr)();
354f4a2713aSLionel Sambuc // CHECK: define void @"\01?callMemberPointerMultiple@@{{.*}} {
355f4a2713aSLionel Sambuc // CHECK:   %[[memptr0:.*]] = extractvalue { i8*, i32 } %{{.*}}, 0
356f4a2713aSLionel Sambuc // CHECK:   %[[memptr1:.*]] = extractvalue { i8*, i32 } %{{.*}}, 1
357f4a2713aSLionel Sambuc // CHECK:   %[[this_adjusted:.*]] = getelementptr inbounds i8* %{{.*}}, i32 %[[memptr1]]
358f4a2713aSLionel Sambuc // CHECK:   %[[this:.*]] = bitcast i8* %[[this_adjusted]] to {{.*}}
359f4a2713aSLionel Sambuc // CHECK:   %[[fptr:.*]] = bitcast i8* %[[memptr0]] to {{.*}}
360f4a2713aSLionel Sambuc // CHECK:   call x86_thiscallcc void %[[fptr]](%{{.*}} %[[this]])
361f4a2713aSLionel Sambuc // CHECK:   ret void
362f4a2713aSLionel Sambuc // CHECK: }
363f4a2713aSLionel Sambuc }
364f4a2713aSLionel Sambuc 
callMemberPointerVirtualBase(Virtual * o,void (Virtual::* memptr)())365f4a2713aSLionel Sambuc void callMemberPointerVirtualBase(Virtual *o, void (Virtual::*memptr)()) {
366f4a2713aSLionel Sambuc   (o->*memptr)();
367f4a2713aSLionel Sambuc // This shares a lot with virtual data member pointers.
368f4a2713aSLionel Sambuc // CHECK: define void @"\01?callMemberPointerVirtualBase@@{{.*}} {
369f4a2713aSLionel Sambuc // CHECK:   %[[memptr0:.*]] = extractvalue { i8*, i32, i32 } %{{.*}}, 0
370f4a2713aSLionel Sambuc // CHECK:   %[[memptr1:.*]] = extractvalue { i8*, i32, i32 } %{{.*}}, 1
371f4a2713aSLionel Sambuc // CHECK:   %[[memptr2:.*]] = extractvalue { i8*, i32, i32 } %{{.*}}, 2
372f4a2713aSLionel Sambuc // CHECK:   %[[vbptr:.*]] = getelementptr inbounds i8* %{{.*}}, i32 0
373*0a6a1f1dSLionel Sambuc // CHECK:   %[[vbptr_a:.*]] = bitcast i8* %[[vbptr]] to i32**
374*0a6a1f1dSLionel Sambuc // CHECK:   %[[vbtable:.*]] = load i32** %[[vbptr_a:.*]]
375*0a6a1f1dSLionel Sambuc // CHECK:   %[[memptr2_shr:.*]] = ashr exact i32 %[[memptr2]], 2
376*0a6a1f1dSLionel Sambuc // CHECK:   %[[v7:.*]] = getelementptr inbounds i32* %[[vbtable]], i32 %[[memptr2_shr]]
377*0a6a1f1dSLionel Sambuc // CHECK:   %[[vbase_offs:.*]] = load i32* %[[v7]]
378f4a2713aSLionel Sambuc // CHECK:   %[[v10:.*]] = getelementptr inbounds i8* %[[vbptr]], i32 %[[vbase_offs]]
379f4a2713aSLionel Sambuc // CHECK:   %[[this_adjusted:.*]] = getelementptr inbounds i8* %[[v10]], i32 %[[memptr1]]
380f4a2713aSLionel Sambuc // CHECK:   %[[fptr:.*]] = bitcast i8* %[[memptr0]] to void ({{.*}})
381f4a2713aSLionel Sambuc // CHECK:   %[[this:.*]] = bitcast i8* %[[this_adjusted]] to {{.*}}
382f4a2713aSLionel Sambuc // CHECK:   call x86_thiscallcc void %[[fptr]](%{{.*}} %[[this]])
383f4a2713aSLionel Sambuc // CHECK:   ret void
384f4a2713aSLionel Sambuc // CHECK: }
385f4a2713aSLionel Sambuc }
386f4a2713aSLionel Sambuc 
compareSingleFunctionMemptr(void (Single::* l)(),void (Single::* r)())387f4a2713aSLionel Sambuc bool compareSingleFunctionMemptr(void (Single::*l)(), void (Single::*r)()) {
388f4a2713aSLionel Sambuc   return l == r;
389f4a2713aSLionel Sambuc // Should only be one comparison here.
390f4a2713aSLionel Sambuc // CHECK: define zeroext i1 @"\01?compareSingleFunctionMemptr@@YA_NP8Single@@AEXXZ0@Z"{{.*}} {
391f4a2713aSLionel Sambuc // CHECK-NOT: icmp
392f4a2713aSLionel Sambuc // CHECK:   %[[r:.*]] = icmp eq
393f4a2713aSLionel Sambuc // CHECK-NOT: icmp
394f4a2713aSLionel Sambuc // CHECK:   ret i1 %[[r]]
395f4a2713aSLionel Sambuc // CHECK: }
396*0a6a1f1dSLionel Sambuc 
397*0a6a1f1dSLionel Sambuc // X64-LABEL: define zeroext i1 @"\01?compareSingleFunctionMemptr@@
398*0a6a1f1dSLionel Sambuc // X64:             (i8* %{{[^,]*}}, i8* %{{[^)]*}})
399f4a2713aSLionel Sambuc }
400f4a2713aSLionel Sambuc 
compareNeqSingleFunctionMemptr(void (Single::* l)(),void (Single::* r)())401f4a2713aSLionel Sambuc bool compareNeqSingleFunctionMemptr(void (Single::*l)(), void (Single::*r)()) {
402f4a2713aSLionel Sambuc   return l != r;
403f4a2713aSLionel Sambuc // Should only be one comparison here.
404f4a2713aSLionel Sambuc // CHECK: define zeroext i1 @"\01?compareNeqSingleFunctionMemptr@@YA_NP8Single@@AEXXZ0@Z"{{.*}} {
405f4a2713aSLionel Sambuc // CHECK-NOT: icmp
406f4a2713aSLionel Sambuc // CHECK:   %[[r:.*]] = icmp ne
407f4a2713aSLionel Sambuc // CHECK-NOT: icmp
408f4a2713aSLionel Sambuc // CHECK:   ret i1 %[[r]]
409f4a2713aSLionel Sambuc // CHECK: }
410f4a2713aSLionel Sambuc }
411f4a2713aSLionel Sambuc 
unspecFuncMemptrEq(void (Unspecified::* l)(),void (Unspecified::* r)())412f4a2713aSLionel Sambuc bool unspecFuncMemptrEq(void (Unspecified::*l)(), void (Unspecified::*r)()) {
413f4a2713aSLionel Sambuc   return l == r;
414f4a2713aSLionel Sambuc // CHECK: define zeroext i1 @"\01?unspecFuncMemptrEq@@YA_NP8Unspecified@@AEXXZ0@Z"{{.*}} {
415f4a2713aSLionel Sambuc // CHECK:   %[[lhs0:.*]] = extractvalue { i8*, i32, i32, i32 } %[[l:.*]], 0
416f4a2713aSLionel Sambuc // CHECK:   %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[r:.*]], 0
417f4a2713aSLionel Sambuc // CHECK:   %[[cmp0:.*]] = icmp eq i8* %[[lhs0]], %{{.*}}
418f4a2713aSLionel Sambuc // CHECK:   %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[l]], 1
419f4a2713aSLionel Sambuc // CHECK:   %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[r]], 1
420f4a2713aSLionel Sambuc // CHECK:   %[[cmp1:.*]] = icmp eq i32
421f4a2713aSLionel Sambuc // CHECK:   %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[l]], 2
422f4a2713aSLionel Sambuc // CHECK:   %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[r]], 2
423f4a2713aSLionel Sambuc // CHECK:   %[[cmp2:.*]] = icmp eq i32
424f4a2713aSLionel Sambuc // CHECK:   %[[res12:.*]] = and i1 %[[cmp1]], %[[cmp2]]
425f4a2713aSLionel Sambuc // CHECK:   %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[l]], 3
426f4a2713aSLionel Sambuc // CHECK:   %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[r]], 3
427f4a2713aSLionel Sambuc // CHECK:   %[[cmp3:.*]] = icmp eq i32
428f4a2713aSLionel Sambuc // CHECK:   %[[res123:.*]] = and i1 %[[res12]], %[[cmp3]]
429f4a2713aSLionel Sambuc // CHECK:   %[[iszero:.*]] = icmp eq i8* %[[lhs0]], null
430f4a2713aSLionel Sambuc // CHECK:   %[[bits_or_null:.*]] = or i1 %[[res123]], %[[iszero]]
431f4a2713aSLionel Sambuc // CHECK:   %{{.*}} = and i1 %[[bits_or_null]], %[[cmp0]]
432f4a2713aSLionel Sambuc // CHECK:   ret i1 %{{.*}}
433f4a2713aSLionel Sambuc // CHECK: }
434*0a6a1f1dSLionel Sambuc 
435*0a6a1f1dSLionel Sambuc // X64-LABEL: define zeroext i1 @"\01?unspecFuncMemptrEq@@
436*0a6a1f1dSLionel Sambuc // X64:             ({ i8*, i32, i32, i32 }*, { i8*, i32, i32, i32 }*)
437f4a2713aSLionel Sambuc }
438f4a2713aSLionel Sambuc 
unspecFuncMemptrNeq(void (Unspecified::* l)(),void (Unspecified::* r)())439f4a2713aSLionel Sambuc bool unspecFuncMemptrNeq(void (Unspecified::*l)(), void (Unspecified::*r)()) {
440f4a2713aSLionel Sambuc   return l != r;
441f4a2713aSLionel Sambuc // CHECK: define zeroext i1 @"\01?unspecFuncMemptrNeq@@YA_NP8Unspecified@@AEXXZ0@Z"{{.*}} {
442f4a2713aSLionel Sambuc // CHECK:   %[[lhs0:.*]] = extractvalue { i8*, i32, i32, i32 } %[[l:.*]], 0
443f4a2713aSLionel Sambuc // CHECK:   %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[r:.*]], 0
444f4a2713aSLionel Sambuc // CHECK:   %[[cmp0:.*]] = icmp ne i8* %[[lhs0]], %{{.*}}
445f4a2713aSLionel Sambuc // CHECK:   %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[l]], 1
446f4a2713aSLionel Sambuc // CHECK:   %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[r]], 1
447f4a2713aSLionel Sambuc // CHECK:   %[[cmp1:.*]] = icmp ne i32
448f4a2713aSLionel Sambuc // CHECK:   %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[l]], 2
449f4a2713aSLionel Sambuc // CHECK:   %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[r]], 2
450f4a2713aSLionel Sambuc // CHECK:   %[[cmp2:.*]] = icmp ne i32
451f4a2713aSLionel Sambuc // CHECK:   %[[res12:.*]] = or i1 %[[cmp1]], %[[cmp2]]
452f4a2713aSLionel Sambuc // CHECK:   %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[l]], 3
453f4a2713aSLionel Sambuc // CHECK:   %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[r]], 3
454f4a2713aSLionel Sambuc // CHECK:   %[[cmp3:.*]] = icmp ne i32
455f4a2713aSLionel Sambuc // CHECK:   %[[res123:.*]] = or i1 %[[res12]], %[[cmp3]]
456f4a2713aSLionel Sambuc // CHECK:   %[[iszero:.*]] = icmp ne i8* %[[lhs0]], null
457f4a2713aSLionel Sambuc // CHECK:   %[[bits_or_null:.*]] = and i1 %[[res123]], %[[iszero]]
458f4a2713aSLionel Sambuc // CHECK:   %{{.*}} = or i1 %[[bits_or_null]], %[[cmp0]]
459f4a2713aSLionel Sambuc // CHECK:   ret i1 %{{.*}}
460f4a2713aSLionel Sambuc // CHECK: }
461f4a2713aSLionel Sambuc }
462f4a2713aSLionel Sambuc 
unspecDataMemptrEq(int Unspecified::* l,int Unspecified::* r)463f4a2713aSLionel Sambuc bool unspecDataMemptrEq(int Unspecified::*l, int Unspecified::*r) {
464f4a2713aSLionel Sambuc   return l == r;
465f4a2713aSLionel Sambuc // CHECK: define zeroext i1 @"\01?unspecDataMemptrEq@@YA_NPQUnspecified@@H0@Z"{{.*}} {
466f4a2713aSLionel Sambuc // CHECK:   extractvalue { i32, i32, i32 } %{{.*}}, 0
467f4a2713aSLionel Sambuc // CHECK:   extractvalue { i32, i32, i32 } %{{.*}}, 0
468f4a2713aSLionel Sambuc // CHECK:   icmp eq i32
469f4a2713aSLionel Sambuc // CHECK:   extractvalue { i32, i32, i32 } %{{.*}}, 1
470f4a2713aSLionel Sambuc // CHECK:   extractvalue { i32, i32, i32 } %{{.*}}, 1
471f4a2713aSLionel Sambuc // CHECK:   icmp eq i32
472f4a2713aSLionel Sambuc // CHECK:   extractvalue { i32, i32, i32 } %{{.*}}, 2
473f4a2713aSLionel Sambuc // CHECK:   extractvalue { i32, i32, i32 } %{{.*}}, 2
474f4a2713aSLionel Sambuc // CHECK:   icmp eq i32
475f4a2713aSLionel Sambuc // CHECK:   and i1
476f4a2713aSLionel Sambuc // CHECK:   and i1
477f4a2713aSLionel Sambuc // CHECK:   ret i1
478f4a2713aSLionel Sambuc // CHECK: }
479*0a6a1f1dSLionel Sambuc 
480*0a6a1f1dSLionel Sambuc // X64-LABEL: define zeroext i1 @"\01?unspecDataMemptrEq@@
481*0a6a1f1dSLionel Sambuc // X64:             ({ i32, i32, i32 }*, { i32, i32, i32 }*)
482f4a2713aSLionel Sambuc }
483f4a2713aSLionel Sambuc 
convertB2FuncToMultiple(void (B2::* mp)())484f4a2713aSLionel Sambuc void (Multiple::*convertB2FuncToMultiple(void (B2::*mp)()))() {
485f4a2713aSLionel Sambuc   return mp;
486f4a2713aSLionel Sambuc // CHECK: define i64 @"\01?convertB2FuncToMultiple@@YAP8Multiple@@AEXXZP8B2@@AEXXZ@Z"{{.*}} {
487f4a2713aSLionel Sambuc // CHECK:   store
488f4a2713aSLionel Sambuc // CHECK:   %[[mp:.*]] = load i8** %{{.*}}, align 4
489f4a2713aSLionel Sambuc // CHECK:   icmp ne i8* %[[mp]], null
490f4a2713aSLionel Sambuc // CHECK:   br i1 %{{.*}} label %{{.*}}, label %{{.*}}
491f4a2713aSLionel Sambuc //
492f4a2713aSLionel Sambuc //        memptr.convert:                                   ; preds = %entry
493f4a2713aSLionel Sambuc // CHECK:   insertvalue { i8*, i32 } undef, i8* %[[mp]], 0
494f4a2713aSLionel Sambuc // CHECK:   insertvalue { i8*, i32 } %{{.*}}, i32 4, 1
495f4a2713aSLionel Sambuc // CHECK:   br label
496f4a2713aSLionel Sambuc //
497f4a2713aSLionel Sambuc //        memptr.converted:                                 ; preds = %memptr.convert, %entry
498f4a2713aSLionel Sambuc // CHECK:   phi { i8*, i32 } [ zeroinitializer, %{{.*}} ], [ {{.*}} ]
499f4a2713aSLionel Sambuc // CHECK: }
500f4a2713aSLionel Sambuc }
501f4a2713aSLionel Sambuc 
convertMultipleFuncToB2(void (Multiple::* mp)())502f4a2713aSLionel Sambuc void (B2::*convertMultipleFuncToB2(void (Multiple::*mp)()))() {
503f4a2713aSLionel Sambuc // FIXME: cl emits warning C4407 on this code because of the representation
504f4a2713aSLionel Sambuc // change.  We might want to do the same.
505f4a2713aSLionel Sambuc   return static_cast<void (B2::*)()>(mp);
506f4a2713aSLionel Sambuc // FIXME: We should return i8* instead of i32 here.  The ptrtoint cast prevents
507f4a2713aSLionel Sambuc // LLVM from optimizing away the branch.  This is likely a bug in
508f4a2713aSLionel Sambuc // lib/CodeGen/TargetInfo.cpp with how we classify memptr types for returns.
509f4a2713aSLionel Sambuc //
510f4a2713aSLionel Sambuc // CHECK: define i32 @"\01?convertMultipleFuncToB2@@YAP8B2@@AEXXZP8Multiple@@AEXXZ@Z"{{.*}} {
511f4a2713aSLionel Sambuc // CHECK:   store
512*0a6a1f1dSLionel Sambuc // CHECK:   %[[src:.*]] = load { i8*, i32 }* %{{.*}}, align 8
513f4a2713aSLionel Sambuc // CHECK:   extractvalue { i8*, i32 } %[[src]], 0
514f4a2713aSLionel Sambuc // CHECK:   icmp ne i8* %{{.*}}, null
515f4a2713aSLionel Sambuc // CHECK:   br i1 %{{.*}}, label %{{.*}}, label %{{.*}}
516f4a2713aSLionel Sambuc //
517f4a2713aSLionel Sambuc //        memptr.convert:                                   ; preds = %entry
518f4a2713aSLionel Sambuc // CHECK:   %[[fp:.*]] = extractvalue { i8*, i32 } %[[src]], 0
519f4a2713aSLionel Sambuc // CHECK:   br label
520f4a2713aSLionel Sambuc //
521f4a2713aSLionel Sambuc //        memptr.converted:                                 ; preds = %memptr.convert, %entry
522f4a2713aSLionel Sambuc // CHECK:   phi i8* [ null, %{{.*}} ], [ %[[fp]], %{{.*}} ]
523f4a2713aSLionel Sambuc // CHECK: }
524f4a2713aSLionel Sambuc }
525f4a2713aSLionel Sambuc 
526f4a2713aSLionel Sambuc namespace Test1 {
527f4a2713aSLionel Sambuc 
528f4a2713aSLionel Sambuc struct A { int a; };
529f4a2713aSLionel Sambuc struct B { int b; };
530f4a2713aSLionel Sambuc struct C : virtual A { int c; };
531f4a2713aSLionel Sambuc struct D : B, C { int d; };
532f4a2713aSLionel Sambuc 
convertCToD(void (C::* mp)())533f4a2713aSLionel Sambuc void (D::*convertCToD(void (C::*mp)()))() {
534f4a2713aSLionel Sambuc   return mp;
535f4a2713aSLionel Sambuc // CHECK: define void @"\01?convertCToD@Test1@@YAP8D@1@AEXXZP8C@1@AEXXZ@Z"{{.*}} {
536f4a2713aSLionel Sambuc // CHECK:   store
537*0a6a1f1dSLionel Sambuc // CHECK:   load { i8*, i32, i32 }* %{{.*}}, align 8
538f4a2713aSLionel Sambuc // CHECK:   extractvalue { i8*, i32, i32 } %{{.*}}, 0
539f4a2713aSLionel Sambuc // CHECK:   icmp ne i8* %{{.*}}, null
540f4a2713aSLionel Sambuc // CHECK:   br i1 %{{.*}}, label %{{.*}}, label %{{.*}}
541f4a2713aSLionel Sambuc //
542f4a2713aSLionel Sambuc //        memptr.convert:                                   ; preds = %entry
543f4a2713aSLionel Sambuc // CHECK:   extractvalue { i8*, i32, i32 } %{{.*}}, 0
544f4a2713aSLionel Sambuc // CHECK:   extractvalue { i8*, i32, i32 } %{{.*}}, 1
545f4a2713aSLionel Sambuc // CHECK:   extractvalue { i8*, i32, i32 } %{{.*}}, 2
546f4a2713aSLionel Sambuc // CHECK:   %[[adj:.*]] = add nsw i32 %{{.*}}, 4
547f4a2713aSLionel Sambuc // CHECK:   insertvalue { i8*, i32, i32 } undef, i8* {{.*}}, 0
548f4a2713aSLionel Sambuc // CHECK:   insertvalue { i8*, i32, i32 } {{.*}}, i32 %[[adj]], 1
549f4a2713aSLionel Sambuc // CHECK:   insertvalue { i8*, i32, i32 } {{.*}}, i32 {{.*}}, 2
550f4a2713aSLionel Sambuc // CHECK:   br label
551f4a2713aSLionel Sambuc //
552f4a2713aSLionel Sambuc //        memptr.converted:                                 ; preds = %memptr.convert, %entry
553f4a2713aSLionel Sambuc // CHECK:   phi { i8*, i32, i32 } [ { i8* null, i32 0, i32 -1 }, {{.*}} ], [ {{.*}} ]
554f4a2713aSLionel Sambuc // CHECK: }
555f4a2713aSLionel Sambuc }
556f4a2713aSLionel Sambuc 
557f4a2713aSLionel Sambuc }
558f4a2713aSLionel Sambuc 
559f4a2713aSLionel Sambuc namespace Test2 {
560f4a2713aSLionel Sambuc // Test that we dynamically convert between different null reps.
561f4a2713aSLionel Sambuc 
562f4a2713aSLionel Sambuc struct A { int a; };
563f4a2713aSLionel Sambuc struct B : A { int b; };
564f4a2713aSLionel Sambuc struct C : A {
565f4a2713aSLionel Sambuc   int c;
566f4a2713aSLionel Sambuc   virtual void hasVfPtr();
567f4a2713aSLionel Sambuc };
568f4a2713aSLionel Sambuc 
reinterpret(int B::* mp)569f4a2713aSLionel Sambuc int A::*reinterpret(int B::*mp) {
570f4a2713aSLionel Sambuc   return reinterpret_cast<int A::*>(mp);
571f4a2713aSLionel Sambuc // CHECK: define i32 @"\01?reinterpret@Test2@@YAPQA@1@HPQB@1@H@Z"{{.*}}  {
572f4a2713aSLionel Sambuc // CHECK-NOT: select
573f4a2713aSLionel Sambuc // CHECK:   ret i32
574f4a2713aSLionel Sambuc // CHECK: }
575f4a2713aSLionel Sambuc }
576f4a2713aSLionel Sambuc 
reinterpret(int C::* mp)577f4a2713aSLionel Sambuc int A::*reinterpret(int C::*mp) {
578f4a2713aSLionel Sambuc   return reinterpret_cast<int A::*>(mp);
579f4a2713aSLionel Sambuc // CHECK: define i32 @"\01?reinterpret@Test2@@YAPQA@1@HPQC@1@H@Z"{{.*}}  {
580f4a2713aSLionel Sambuc // CHECK:   %[[mp:.*]] = load i32*
581f4a2713aSLionel Sambuc // CHECK:   %[[cmp:.*]] = icmp ne i32 %[[mp]], 0
582f4a2713aSLionel Sambuc // CHECK:   select i1 %[[cmp]], i32 %[[mp]], i32 -1
583f4a2713aSLionel Sambuc // CHECK: }
584f4a2713aSLionel Sambuc }
585f4a2713aSLionel Sambuc 
586f4a2713aSLionel Sambuc }
587*0a6a1f1dSLionel Sambuc 
588*0a6a1f1dSLionel Sambuc namespace Test3 {
589*0a6a1f1dSLionel Sambuc // Make sure we cast 'this' to i8* before using GEP.
590*0a6a1f1dSLionel Sambuc 
591*0a6a1f1dSLionel Sambuc struct A {
592*0a6a1f1dSLionel Sambuc   int a;
593*0a6a1f1dSLionel Sambuc   int b;
594*0a6a1f1dSLionel Sambuc };
595*0a6a1f1dSLionel Sambuc 
load_data(A * a,int A::* mp)596*0a6a1f1dSLionel Sambuc int *load_data(A *a, int A::*mp) {
597*0a6a1f1dSLionel Sambuc   return &(a->*mp);
598*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define i32* @"\01?load_data@Test3@@YAPAHPAUA@1@PQ21@H@Z"{{.*}}  {
599*0a6a1f1dSLionel Sambuc // CHECK:    %[[a:.*]] = load %"struct.Test3::A"** %{{.*}}, align 4
600*0a6a1f1dSLionel Sambuc // CHECK:    %[[mp:.*]] = load i32* %{{.*}}, align 4
601*0a6a1f1dSLionel Sambuc // CHECK:    %[[a_i8:.*]] = bitcast %"struct.Test3::A"* %[[a]] to i8*
602*0a6a1f1dSLionel Sambuc // CHECK:    getelementptr inbounds i8* %[[a_i8]], i32 %[[mp]]
603*0a6a1f1dSLionel Sambuc // CHECK: }
604*0a6a1f1dSLionel Sambuc }
605*0a6a1f1dSLionel Sambuc 
606*0a6a1f1dSLionel Sambuc }
607*0a6a1f1dSLionel Sambuc 
608*0a6a1f1dSLionel Sambuc namespace Test4 {
609*0a6a1f1dSLionel Sambuc 
610*0a6a1f1dSLionel Sambuc struct A        { virtual void f(); };
611*0a6a1f1dSLionel Sambuc struct B        { virtual void g(); };
612*0a6a1f1dSLionel Sambuc struct C : A, B { virtual void g(); };
613*0a6a1f1dSLionel Sambuc 
getmp()614*0a6a1f1dSLionel Sambuc void (C::*getmp())() {
615*0a6a1f1dSLionel Sambuc   return &C::g;
616*0a6a1f1dSLionel Sambuc }
617*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define i64 @"\01?getmp@Test4@@YAP8C@1@AEXXZXZ"()
618*0a6a1f1dSLionel Sambuc // CHECK: store { i8*, i32 } { i8* bitcast (void (%"struct.Test4::C"*, ...)* @"\01??_9C@Test4@@$BA@AE" to i8*), i32 4 }, { i8*, i32 }* %{{.*}}
619*0a6a1f1dSLionel Sambuc //
620*0a6a1f1dSLionel Sambuc 
621*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define linkonce_odr x86_thiscallcc void @"\01??_9C@Test4@@$BA@AE"(%"struct.Test4::C"* %this, ...)
622*0a6a1f1dSLionel Sambuc // CHECK-NOT:  getelementptr
623*0a6a1f1dSLionel Sambuc // CHECK:  load void (%"struct.Test4::C"*, ...)*** %{{.*}}
624*0a6a1f1dSLionel Sambuc // CHECK:  getelementptr inbounds void (%"struct.Test4::C"*, ...)** %{{.*}}, i64 0
625*0a6a1f1dSLionel Sambuc // CHECK-NOT:  getelementptr
626*0a6a1f1dSLionel Sambuc // CHECK:  musttail call x86_thiscallcc void (%"struct.Test4::C"*, ...)* %
627*0a6a1f1dSLionel Sambuc 
628*0a6a1f1dSLionel Sambuc }
629*0a6a1f1dSLionel Sambuc 
630*0a6a1f1dSLionel Sambuc namespace pr20007 {
631*0a6a1f1dSLionel Sambuc struct A {
632*0a6a1f1dSLionel Sambuc   void f();
633*0a6a1f1dSLionel Sambuc   void f(int);
634*0a6a1f1dSLionel Sambuc };
635*0a6a1f1dSLionel Sambuc struct B : public A {};
test()636*0a6a1f1dSLionel Sambuc void test() { void (B::*a)() = &B::f; }
637*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define void @"\01?test@pr20007@@YAXXZ"
638*0a6a1f1dSLionel Sambuc // CHECK: store i8* bitcast (void (%"struct.pr20007::A"*)* @"\01?f@A@pr20007@@QAEXXZ" to i8*)
639*0a6a1f1dSLionel Sambuc }
640*0a6a1f1dSLionel Sambuc 
641*0a6a1f1dSLionel Sambuc namespace pr20007_kw {
642*0a6a1f1dSLionel Sambuc struct A {
643*0a6a1f1dSLionel Sambuc   void f();
644*0a6a1f1dSLionel Sambuc   void f(int);
645*0a6a1f1dSLionel Sambuc };
646*0a6a1f1dSLionel Sambuc struct __single_inheritance B;
647*0a6a1f1dSLionel Sambuc struct B : public A {};
test()648*0a6a1f1dSLionel Sambuc void test() { void (B::*a)() = &B::f; }
649*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define void @"\01?test@pr20007_kw@@YAXXZ"
650*0a6a1f1dSLionel Sambuc // CHECK: store i8* bitcast (void (%"struct.pr20007_kw::A"*)* @"\01?f@A@pr20007_kw@@QAEXXZ" to i8*)
651*0a6a1f1dSLionel Sambuc }
652*0a6a1f1dSLionel Sambuc 
653*0a6a1f1dSLionel Sambuc namespace pr20007_pragma {
654*0a6a1f1dSLionel Sambuc struct A {
655*0a6a1f1dSLionel Sambuc   void f();
656*0a6a1f1dSLionel Sambuc   void f(int);
657*0a6a1f1dSLionel Sambuc };
658*0a6a1f1dSLionel Sambuc struct B : public A {};
test()659*0a6a1f1dSLionel Sambuc void test() { (void)(void (B::*)()) &B::f; }
660*0a6a1f1dSLionel Sambuc #pragma pointers_to_members(full_generality, virtual_inheritance)
661*0a6a1f1dSLionel Sambuc static_assert(sizeof(int B::*) == 4, "");
662*0a6a1f1dSLionel Sambuc static_assert(sizeof(int A::*) == 4, "");
663*0a6a1f1dSLionel Sambuc #pragma pointers_to_members(best_case)
664*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define void @"\01?test@pr20007_pragma@@YAXXZ"
665*0a6a1f1dSLionel Sambuc }
666*0a6a1f1dSLionel Sambuc 
667*0a6a1f1dSLionel Sambuc namespace pr20007_pragma2 {
668*0a6a1f1dSLionel Sambuc struct A {
669*0a6a1f1dSLionel Sambuc };
670*0a6a1f1dSLionel Sambuc struct B : public A {
671*0a6a1f1dSLionel Sambuc   void f();
672*0a6a1f1dSLionel Sambuc };
test()673*0a6a1f1dSLionel Sambuc void test() { (void)&B::f; }
674*0a6a1f1dSLionel Sambuc #pragma pointers_to_members(full_generality, virtual_inheritance)
675*0a6a1f1dSLionel Sambuc static_assert(sizeof(int B::*) == 4, "");
676*0a6a1f1dSLionel Sambuc static_assert(sizeof(int A::*) == 12, "");
677*0a6a1f1dSLionel Sambuc #pragma pointers_to_members(best_case)
678*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define void @"\01?test@pr20007_pragma2@@YAXXZ"
679*0a6a1f1dSLionel Sambuc }
680*0a6a1f1dSLionel Sambuc 
681*0a6a1f1dSLionel Sambuc namespace pr19987 {
682*0a6a1f1dSLionel Sambuc template <typename T>
683*0a6a1f1dSLionel Sambuc struct S {
684*0a6a1f1dSLionel Sambuc   int T::*x;
685*0a6a1f1dSLionel Sambuc };
686*0a6a1f1dSLionel Sambuc 
687*0a6a1f1dSLionel Sambuc struct U : S<U> {};
688*0a6a1f1dSLionel Sambuc 
689*0a6a1f1dSLionel Sambuc static_assert(sizeof(S<U>::x) == 12, "");
690*0a6a1f1dSLionel Sambuc }
691*0a6a1f1dSLionel Sambuc 
692*0a6a1f1dSLionel Sambuc #else
693*0a6a1f1dSLionel Sambuc struct __virtual_inheritance A;
694*0a6a1f1dSLionel Sambuc #ifdef MEMFUN
foo(A * a,int (A::* mp)())695*0a6a1f1dSLionel Sambuc int foo(A *a, int (A::*mp)()) {
696*0a6a1f1dSLionel Sambuc     return (a->*mp)(); // expected-error{{requires a complete class type}}
697*0a6a1f1dSLionel Sambuc }
698*0a6a1f1dSLionel Sambuc #else
foo(A * a,int A::* mp)699*0a6a1f1dSLionel Sambuc int foo(A *a, int A::*mp) {
700*0a6a1f1dSLionel Sambuc     return a->*mp; // expected-error{{requires a complete class type}}
701*0a6a1f1dSLionel Sambuc }
702*0a6a1f1dSLionel Sambuc #endif
703*0a6a1f1dSLionel Sambuc #endif
704