xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/microsoft-abi-member-pointers.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fno-rtti -emit-llvm %s -o - -cxx-abi microsoft -triple=i386-pc-win32 | FileCheck %s
2*f4a2713aSLionel Sambuc // FIXME: Test x86_64 member pointers when codegen no longer asserts on records
3*f4a2713aSLionel Sambuc // with virtual bases.
4*f4a2713aSLionel Sambuc 
5*f4a2713aSLionel Sambuc struct B1 {
6*f4a2713aSLionel Sambuc   void foo();
7*f4a2713aSLionel Sambuc   int b;
8*f4a2713aSLionel Sambuc };
9*f4a2713aSLionel Sambuc struct B2 {
10*f4a2713aSLionel Sambuc   int b2;
11*f4a2713aSLionel Sambuc   void foo();
12*f4a2713aSLionel Sambuc };
13*f4a2713aSLionel Sambuc struct Single : B1 {
14*f4a2713aSLionel Sambuc   void foo();
15*f4a2713aSLionel Sambuc };
16*f4a2713aSLionel Sambuc struct Multiple : B1, B2 {
17*f4a2713aSLionel Sambuc   int m;
18*f4a2713aSLionel Sambuc   void foo();
19*f4a2713aSLionel Sambuc };
20*f4a2713aSLionel Sambuc struct Virtual : virtual B1 {
21*f4a2713aSLionel Sambuc   int v;
22*f4a2713aSLionel Sambuc   void foo();
23*f4a2713aSLionel Sambuc };
24*f4a2713aSLionel Sambuc 
25*f4a2713aSLionel Sambuc struct POD {
26*f4a2713aSLionel Sambuc   int a;
27*f4a2713aSLionel Sambuc   int b;
28*f4a2713aSLionel Sambuc };
29*f4a2713aSLionel Sambuc 
30*f4a2713aSLionel Sambuc struct Polymorphic {
31*f4a2713aSLionel Sambuc   virtual void myVirtual();
32*f4a2713aSLionel Sambuc   int a;
33*f4a2713aSLionel Sambuc   int b;
34*f4a2713aSLionel Sambuc };
35*f4a2713aSLionel Sambuc 
36*f4a2713aSLionel Sambuc // This class uses the virtual inheritance model, yet its vbptr offset is not 0.
37*f4a2713aSLionel Sambuc // We still use zero for the null field offset, despite it being a valid field
38*f4a2713aSLionel Sambuc // offset.
39*f4a2713aSLionel Sambuc struct NonZeroVBPtr : POD, Virtual {
40*f4a2713aSLionel Sambuc   int n;
41*f4a2713aSLionel Sambuc   void foo();
42*f4a2713aSLionel Sambuc };
43*f4a2713aSLionel Sambuc 
44*f4a2713aSLionel Sambuc struct Unspecified;
45*f4a2713aSLionel Sambuc struct UnspecSingle;
46*f4a2713aSLionel Sambuc 
47*f4a2713aSLionel Sambuc // Check that we can lower the LLVM types and get the null initializers right.
48*f4a2713aSLionel Sambuc int Single     ::*s_d_memptr;
49*f4a2713aSLionel Sambuc int Polymorphic::*p_d_memptr;
50*f4a2713aSLionel Sambuc int Multiple   ::*m_d_memptr;
51*f4a2713aSLionel Sambuc int Virtual    ::*v_d_memptr;
52*f4a2713aSLionel Sambuc int NonZeroVBPtr::*n_d_memptr;
53*f4a2713aSLionel Sambuc int Unspecified::*u_d_memptr;
54*f4a2713aSLionel Sambuc int UnspecSingle::*us_d_memptr;
55*f4a2713aSLionel Sambuc // CHECK: @"\01?s_d_memptr@@3PQSingle@@HQ1@" = global i32 -1, align 4
56*f4a2713aSLionel Sambuc // CHECK: @"\01?p_d_memptr@@3PQPolymorphic@@HQ1@" = global i32 0, align 4
57*f4a2713aSLionel Sambuc // CHECK: @"\01?m_d_memptr@@3PQMultiple@@HQ1@" = global i32 -1, align 4
58*f4a2713aSLionel Sambuc // CHECK: @"\01?v_d_memptr@@3PQVirtual@@HQ1@" = global { i32, i32 }
59*f4a2713aSLionel Sambuc // CHECK:   { i32 0, i32 -1 }, align 4
60*f4a2713aSLionel Sambuc // CHECK: @"\01?n_d_memptr@@3PQNonZeroVBPtr@@HQ1@" = global { i32, i32 }
61*f4a2713aSLionel Sambuc // CHECK:   { i32 0, i32 -1 }, align 4
62*f4a2713aSLionel Sambuc // CHECK: @"\01?u_d_memptr@@3PQUnspecified@@HQ1@" = global { i32, i32, i32 }
63*f4a2713aSLionel Sambuc // CHECK:   { i32 0, i32 0, i32 -1 }, align 4
64*f4a2713aSLionel Sambuc // CHECK: @"\01?us_d_memptr@@3PQUnspecSingle@@HQ1@" = global { i32, i32, i32 }
65*f4a2713aSLionel Sambuc // CHECK:   { i32 0, i32 0, i32 -1 }, align 4
66*f4a2713aSLionel Sambuc 
67*f4a2713aSLionel Sambuc void (Single  ::*s_f_memptr)();
68*f4a2713aSLionel Sambuc void (Multiple::*m_f_memptr)();
69*f4a2713aSLionel Sambuc void (Virtual ::*v_f_memptr)();
70*f4a2713aSLionel Sambuc // CHECK: @"\01?s_f_memptr@@3P8Single@@AEXXZQ1@" = global i8* null, align 4
71*f4a2713aSLionel Sambuc // CHECK: @"\01?m_f_memptr@@3P8Multiple@@AEXXZQ1@" = global { i8*, i32 } zeroinitializer, align 4
72*f4a2713aSLionel Sambuc // CHECK: @"\01?v_f_memptr@@3P8Virtual@@AEXXZQ1@" = global { i8*, i32, i32 } zeroinitializer, align 4
73*f4a2713aSLionel Sambuc 
74*f4a2713aSLionel Sambuc // We can define Unspecified after locking in the inheritance model.
75*f4a2713aSLionel Sambuc struct Unspecified : Multiple, Virtual {
76*f4a2713aSLionel Sambuc   void foo();
77*f4a2713aSLionel Sambuc   int u;
78*f4a2713aSLionel Sambuc };
79*f4a2713aSLionel Sambuc 
80*f4a2713aSLionel Sambuc struct UnspecSingle {
81*f4a2713aSLionel Sambuc   void foo();
82*f4a2713aSLionel Sambuc };
83*f4a2713aSLionel Sambuc 
84*f4a2713aSLionel Sambuc // Test memptr emission in a constant expression.
85*f4a2713aSLionel Sambuc namespace Const {
86*f4a2713aSLionel Sambuc void (Single     ::*s_f_mp)() = &Single::foo;
87*f4a2713aSLionel Sambuc void (Multiple   ::*m_f_mp)() = &B2::foo;
88*f4a2713aSLionel Sambuc void (Virtual    ::*v_f_mp)() = &Virtual::foo;
89*f4a2713aSLionel Sambuc void (Unspecified::*u_f_mp)() = &Unspecified::foo;
90*f4a2713aSLionel Sambuc void (UnspecSingle::*us_f_mp)() = &UnspecSingle::foo;
91*f4a2713aSLionel Sambuc // CHECK: @"\01?s_f_mp@Const@@3P8Single@@AEXXZQ2@" =
92*f4a2713aSLionel Sambuc // CHECK:   global i8* bitcast ({{.*}} @"\01?foo@Single@@QAEXXZ" to i8*), align 4
93*f4a2713aSLionel Sambuc // CHECK: @"\01?m_f_mp@Const@@3P8Multiple@@AEXXZQ2@" =
94*f4a2713aSLionel Sambuc // CHECK:   global { i8*, i32 } { i8* bitcast ({{.*}} @"\01?foo@B2@@QAEXXZ" to i8*), i32 4 }, align 4
95*f4a2713aSLionel Sambuc // CHECK: @"\01?v_f_mp@Const@@3P8Virtual@@AEXXZQ2@" =
96*f4a2713aSLionel Sambuc // CHECK:   global { i8*, i32, i32 } { i8* bitcast ({{.*}} @"\01?foo@Virtual@@QAEXXZ" to i8*), i32 0, i32 0 }, align 4
97*f4a2713aSLionel Sambuc // CHECK: @"\01?u_f_mp@Const@@3P8Unspecified@@AEXXZQ2@" =
98*f4a2713aSLionel Sambuc // CHECK:   global { i8*, i32, i32, i32 } { i8* bitcast ({{.*}} @"\01?foo@Unspecified@@QAEXXZ" to i8*), i32 0, i32 12, i32 0 }, align 4
99*f4a2713aSLionel Sambuc // CHECK: @"\01?us_f_mp@Const@@3P8UnspecSingle@@AEXXZQ2@" =
100*f4a2713aSLionel Sambuc // CHECK:   global { i8*, i32, i32, i32 } { i8* bitcast ({{.*}} @"\01?foo@UnspecSingle@@QAEXXZ" to i8*), i32 0, i32 0, i32 0 }, align 4
101*f4a2713aSLionel Sambuc }
102*f4a2713aSLionel Sambuc 
103*f4a2713aSLionel Sambuc namespace CastParam {
104*f4a2713aSLionel Sambuc // This exercises ConstExprEmitter instead of ValueDecl::evaluateValue.  The
105*f4a2713aSLionel Sambuc // extra reinterpret_cast for the parameter type requires more careful folding.
106*f4a2713aSLionel Sambuc // FIXME: Or does it?  If reinterpret_casts are no-ops, we should be able to
107*f4a2713aSLionel Sambuc // strip them in evaluateValue() and just proceed as normal with an APValue.
108*f4a2713aSLionel Sambuc struct A {
109*f4a2713aSLionel Sambuc   int a;
110*f4a2713aSLionel Sambuc   void foo(A *p);
111*f4a2713aSLionel Sambuc };
112*f4a2713aSLionel Sambuc struct B { int b; };
113*f4a2713aSLionel Sambuc struct C : B, A { int c; };
114*f4a2713aSLionel Sambuc 
115*f4a2713aSLionel Sambuc void (A::*ptr1)(void *) = (void (A::*)(void *)) &A::foo;
116*f4a2713aSLionel Sambuc // CHECK: @"\01?ptr1@CastParam@@3P8A@1@AEXPAX@ZQ21@" =
117*f4a2713aSLionel Sambuc // CHECK:   global i8* bitcast (void ({{.*}})* @"\01?foo@A@CastParam@@QAEXPAU12@@Z" to i8*), align 4
118*f4a2713aSLionel Sambuc 
119*f4a2713aSLionel Sambuc // Try a reinterpret_cast followed by a memptr conversion.
120*f4a2713aSLionel Sambuc void (C::*ptr2)(void *) = (void (C::*)(void *)) (void (A::*)(void *)) &A::foo;
121*f4a2713aSLionel Sambuc // CHECK: @"\01?ptr2@CastParam@@3P8C@1@AEXPAX@ZQ21@" =
122*f4a2713aSLionel Sambuc // CHECK:   global { i8*, i32 } { i8* bitcast (void ({{.*}})* @"\01?foo@A@CastParam@@QAEXPAU12@@Z" to i8*), i32 4 }, align 4
123*f4a2713aSLionel Sambuc 
124*f4a2713aSLionel Sambuc void (C::*ptr3)(void *) = (void (C::*)(void *)) (void (A::*)(void *)) (void (A::*)(A *)) 0;
125*f4a2713aSLionel Sambuc // CHECK: @"\01?ptr3@CastParam@@3P8C@1@AEXPAX@ZQ21@" =
126*f4a2713aSLionel Sambuc // CHECK:   global { i8*, i32 } zeroinitializer, align 4
127*f4a2713aSLionel Sambuc 
128*f4a2713aSLionel Sambuc struct D : C {
129*f4a2713aSLionel Sambuc   virtual void isPolymorphic();
130*f4a2713aSLionel Sambuc   int d;
131*f4a2713aSLionel Sambuc };
132*f4a2713aSLionel Sambuc 
133*f4a2713aSLionel Sambuc // Try a cast that changes the inheritance model.  Null for D is 0, but null for
134*f4a2713aSLionel Sambuc // C is -1.  We need the cast to long in order to hit the non-APValue path.
135*f4a2713aSLionel Sambuc int C::*ptr4 = (int C::*) (int D::*) (long D::*) 0;
136*f4a2713aSLionel Sambuc // CHECK: @"\01?ptr4@CastParam@@3PQC@1@HQ21@" = global i32 -1, align 4
137*f4a2713aSLionel Sambuc 
138*f4a2713aSLionel Sambuc // MSVC rejects this but we accept it.
139*f4a2713aSLionel Sambuc int C::*ptr5 = (int C::*) (long D::*) 0;
140*f4a2713aSLionel Sambuc // CHECK: @"\01?ptr5@CastParam@@3PQC@1@HQ21@" = global i32 -1, align 4
141*f4a2713aSLionel Sambuc }
142*f4a2713aSLionel Sambuc 
143*f4a2713aSLionel Sambuc struct UnspecWithVBPtr;
144*f4a2713aSLionel Sambuc int UnspecWithVBPtr::*forceUnspecWithVBPtr;
145*f4a2713aSLionel Sambuc struct UnspecWithVBPtr : B1, virtual B2 {
146*f4a2713aSLionel Sambuc   int u;
147*f4a2713aSLionel Sambuc   void foo();
148*f4a2713aSLionel Sambuc };
149*f4a2713aSLionel Sambuc 
150*f4a2713aSLionel Sambuc // Test emitting non-virtual member pointers in a non-constexpr setting.
151*f4a2713aSLionel Sambuc void EmitNonVirtualMemberPointers() {
152*f4a2713aSLionel Sambuc   void (Single     ::*s_f_memptr)() = &Single::foo;
153*f4a2713aSLionel Sambuc   void (Multiple   ::*m_f_memptr)() = &Multiple::foo;
154*f4a2713aSLionel Sambuc   void (Virtual    ::*v_f_memptr)() = &Virtual::foo;
155*f4a2713aSLionel Sambuc   void (Unspecified::*u_f_memptr)() = &Unspecified::foo;
156*f4a2713aSLionel Sambuc   void (UnspecWithVBPtr::*u2_f_memptr)() = &UnspecWithVBPtr::foo;
157*f4a2713aSLionel Sambuc // CHECK: define void @"\01?EmitNonVirtualMemberPointers@@YAXXZ"() {{.*}} {
158*f4a2713aSLionel Sambuc // CHECK:   alloca i8*, align 4
159*f4a2713aSLionel Sambuc // CHECK:   alloca { i8*, i32 }, align 4
160*f4a2713aSLionel Sambuc // CHECK:   alloca { i8*, i32, i32 }, align 4
161*f4a2713aSLionel Sambuc // CHECK:   alloca { i8*, i32, i32, i32 }, align 4
162*f4a2713aSLionel Sambuc // CHECK:   store i8* bitcast (void (%{{.*}}*)* @"\01?foo@Single@@QAEXXZ" to i8*), i8** %{{.*}}, align 4
163*f4a2713aSLionel Sambuc // CHECK:   store { i8*, i32 }
164*f4a2713aSLionel Sambuc // CHECK:     { i8* bitcast (void (%{{.*}}*)* @"\01?foo@Multiple@@QAEXXZ" to i8*), i32 0 },
165*f4a2713aSLionel Sambuc // CHECK:     { i8*, i32 }* %{{.*}}, align 4
166*f4a2713aSLionel Sambuc // CHECK:   store { i8*, i32, i32 }
167*f4a2713aSLionel Sambuc // CHECK:     { i8* bitcast (void (%{{.*}}*)* @"\01?foo@Virtual@@QAEXXZ" to i8*), i32 0, i32 0 },
168*f4a2713aSLionel Sambuc // CHECK:     { i8*, i32, i32 }* %{{.*}}, align 4
169*f4a2713aSLionel Sambuc // CHECK:   store { i8*, i32, i32, i32 }
170*f4a2713aSLionel Sambuc // CHECK:     { i8* bitcast (void (%{{.*}}*)* @"\01?foo@Unspecified@@QAEXXZ" to i8*), i32 0, i32 12, i32 0 },
171*f4a2713aSLionel Sambuc // CHECK:     { i8*, i32, i32, i32 }* %{{.*}}, align 4
172*f4a2713aSLionel Sambuc // CHECK:   store { i8*, i32, i32, i32 }
173*f4a2713aSLionel Sambuc // CHECK:     { i8* bitcast (void (%{{.*}}*)* @"\01?foo@UnspecWithVBPtr@@QAEXXZ" to i8*),
174*f4a2713aSLionel Sambuc // CHECK:       i32 0, i32 4, i32 0 },
175*f4a2713aSLionel Sambuc // CHECK:     { i8*, i32, i32, i32 }* %{{.*}}, align 4
176*f4a2713aSLionel Sambuc // CHECK:   ret void
177*f4a2713aSLionel Sambuc // CHECK: }
178*f4a2713aSLionel Sambuc }
179*f4a2713aSLionel Sambuc 
180*f4a2713aSLionel Sambuc void podMemPtrs() {
181*f4a2713aSLionel Sambuc   int POD::*memptr;
182*f4a2713aSLionel Sambuc   memptr = &POD::a;
183*f4a2713aSLionel Sambuc   memptr = &POD::b;
184*f4a2713aSLionel Sambuc   if (memptr)
185*f4a2713aSLionel Sambuc     memptr = 0;
186*f4a2713aSLionel Sambuc // Check that member pointers use the right offsets and that null is -1.
187*f4a2713aSLionel Sambuc // CHECK:      define void @"\01?podMemPtrs@@YAXXZ"() {{.*}} {
188*f4a2713aSLionel Sambuc // CHECK:        %[[memptr:.*]] = alloca i32, align 4
189*f4a2713aSLionel Sambuc // CHECK-NEXT:   store i32 0, i32* %[[memptr]], align 4
190*f4a2713aSLionel Sambuc // CHECK-NEXT:   store i32 4, i32* %[[memptr]], align 4
191*f4a2713aSLionel Sambuc // CHECK-NEXT:   %[[memptr_val:.*]] = load i32* %[[memptr]], align 4
192*f4a2713aSLionel Sambuc // CHECK-NEXT:   %{{.*}} = icmp ne i32 %[[memptr_val]], -1
193*f4a2713aSLionel Sambuc // CHECK-NEXT:   br i1 %{{.*}}, label %{{.*}}, label %{{.*}}
194*f4a2713aSLionel Sambuc // CHECK:        store i32 -1, i32* %[[memptr]], align 4
195*f4a2713aSLionel Sambuc // CHECK:        ret void
196*f4a2713aSLionel Sambuc // CHECK:      }
197*f4a2713aSLionel Sambuc }
198*f4a2713aSLionel Sambuc 
199*f4a2713aSLionel Sambuc void polymorphicMemPtrs() {
200*f4a2713aSLionel Sambuc   int Polymorphic::*memptr;
201*f4a2713aSLionel Sambuc   memptr = &Polymorphic::a;
202*f4a2713aSLionel Sambuc   memptr = &Polymorphic::b;
203*f4a2713aSLionel Sambuc   if (memptr)
204*f4a2713aSLionel Sambuc     memptr = 0;
205*f4a2713aSLionel Sambuc // Member pointers for polymorphic classes include the vtable slot in their
206*f4a2713aSLionel Sambuc // offset and use 0 to represent null.
207*f4a2713aSLionel Sambuc // CHECK:      define void @"\01?polymorphicMemPtrs@@YAXXZ"() {{.*}} {
208*f4a2713aSLionel Sambuc // CHECK:        %[[memptr:.*]] = alloca i32, align 4
209*f4a2713aSLionel Sambuc // CHECK-NEXT:   store i32 4, i32* %[[memptr]], align 4
210*f4a2713aSLionel Sambuc // CHECK-NEXT:   store i32 8, i32* %[[memptr]], align 4
211*f4a2713aSLionel Sambuc // CHECK-NEXT:   %[[memptr_val:.*]] = load i32* %[[memptr]], align 4
212*f4a2713aSLionel Sambuc // CHECK-NEXT:   %{{.*}} = icmp ne i32 %[[memptr_val]], 0
213*f4a2713aSLionel Sambuc // CHECK-NEXT:   br i1 %{{.*}}, label %{{.*}}, label %{{.*}}
214*f4a2713aSLionel Sambuc // CHECK:        store i32 0, i32* %[[memptr]], align 4
215*f4a2713aSLionel Sambuc // CHECK:        ret void
216*f4a2713aSLionel Sambuc // CHECK:      }
217*f4a2713aSLionel Sambuc }
218*f4a2713aSLionel Sambuc 
219*f4a2713aSLionel Sambuc bool nullTestDataUnspecified(int Unspecified::*mp) {
220*f4a2713aSLionel Sambuc   return mp;
221*f4a2713aSLionel Sambuc // CHECK: define zeroext i1 @"\01?nullTestDataUnspecified@@YA_NPQUnspecified@@H@Z"{{.*}} {
222*f4a2713aSLionel Sambuc // CHECK:   %{{.*}} = load { i32, i32, i32 }* %{{.*}}, align 4
223*f4a2713aSLionel Sambuc // CHECK:   store { i32, i32, i32 } {{.*}} align 4
224*f4a2713aSLionel Sambuc // CHECK:   %[[mp:.*]] = load { i32, i32, i32 }* %{{.*}}, align 4
225*f4a2713aSLionel Sambuc // CHECK:   %[[mp0:.*]] = extractvalue { i32, i32, i32 } %[[mp]], 0
226*f4a2713aSLionel Sambuc // CHECK:   %[[cmp0:.*]] = icmp ne i32 %[[mp0]], 0
227*f4a2713aSLionel Sambuc // CHECK:   %[[mp1:.*]] = extractvalue { i32, i32, i32 } %[[mp]], 1
228*f4a2713aSLionel Sambuc // CHECK:   %[[cmp1:.*]] = icmp ne i32 %[[mp1]], 0
229*f4a2713aSLionel Sambuc // CHECK:   %[[and0:.*]] = and i1 %[[cmp0]], %[[cmp1]]
230*f4a2713aSLionel Sambuc // CHECK:   %[[mp2:.*]] = extractvalue { i32, i32, i32 } %[[mp]], 2
231*f4a2713aSLionel Sambuc // CHECK:   %[[cmp2:.*]] = icmp ne i32 %[[mp2]], -1
232*f4a2713aSLionel Sambuc // CHECK:   %[[and1:.*]] = and i1 %[[and0]], %[[cmp2]]
233*f4a2713aSLionel Sambuc // CHECK:   ret i1 %[[and1]]
234*f4a2713aSLionel Sambuc // CHECK: }
235*f4a2713aSLionel Sambuc }
236*f4a2713aSLionel Sambuc 
237*f4a2713aSLionel Sambuc bool nullTestFunctionUnspecified(void (Unspecified::*mp)()) {
238*f4a2713aSLionel Sambuc   return mp;
239*f4a2713aSLionel Sambuc // CHECK: define zeroext i1 @"\01?nullTestFunctionUnspecified@@YA_NP8Unspecified@@AEXXZ@Z"{{.*}} {
240*f4a2713aSLionel Sambuc // CHECK:   %{{.*}} = load { i8*, i32, i32, i32 }* %{{.*}}, align 4
241*f4a2713aSLionel Sambuc // CHECK:   store { i8*, i32, i32, i32 } {{.*}} align 4
242*f4a2713aSLionel Sambuc // CHECK:   %[[mp:.*]] = load { i8*, i32, i32, i32 }* %{{.*}}, align 4
243*f4a2713aSLionel Sambuc // CHECK:   %[[mp0:.*]] = extractvalue { i8*, i32, i32, i32 } %[[mp]], 0
244*f4a2713aSLionel Sambuc // CHECK:   %[[cmp0:.*]] = icmp ne i8* %[[mp0]], null
245*f4a2713aSLionel Sambuc // CHECK:   ret i1 %[[cmp0]]
246*f4a2713aSLionel Sambuc // CHECK: }
247*f4a2713aSLionel Sambuc }
248*f4a2713aSLionel Sambuc 
249*f4a2713aSLionel Sambuc int loadDataMemberPointerVirtual(Virtual *o, int Virtual::*memptr) {
250*f4a2713aSLionel Sambuc   return o->*memptr;
251*f4a2713aSLionel Sambuc // Test that we can unpack this aggregate member pointer and load the member
252*f4a2713aSLionel Sambuc // data pointer.
253*f4a2713aSLionel Sambuc // CHECK: define i32 @"\01?loadDataMemberPointerVirtual@@YAHPAUVirtual@@PQ1@H@Z"{{.*}} {
254*f4a2713aSLionel Sambuc // CHECK:   %[[o:.*]] = load %{{.*}}** %{{.*}}, align 4
255*f4a2713aSLionel Sambuc // CHECK:   %[[memptr:.*]] = load { i32, i32 }* %{{.*}}, align 4
256*f4a2713aSLionel Sambuc // CHECK:   %[[memptr0:.*]] = extractvalue { i32, i32 } %[[memptr:.*]], 0
257*f4a2713aSLionel Sambuc // CHECK:   %[[memptr1:.*]] = extractvalue { i32, i32 } %[[memptr:.*]], 1
258*f4a2713aSLionel Sambuc // CHECK:   %[[v6:.*]] = bitcast %{{.*}}* %[[o]] to i8*
259*f4a2713aSLionel Sambuc // CHECK:   %[[vbptr:.*]] = getelementptr inbounds i8* %[[v6]], i32 0
260*f4a2713aSLionel Sambuc // CHECK:   %[[vbptr_a:.*]] = bitcast i8* %[[vbptr]] to i8**
261*f4a2713aSLionel Sambuc // CHECK:   %[[vbtable:.*]] = load i8** %[[vbptr_a:.*]]
262*f4a2713aSLionel Sambuc // CHECK:   %[[v7:.*]] = getelementptr inbounds i8* %[[vbtable]], i32 %[[memptr1]]
263*f4a2713aSLionel Sambuc // CHECK:   %[[v8:.*]] = bitcast i8* %[[v7]] to i32*
264*f4a2713aSLionel Sambuc // CHECK:   %[[vbase_offs:.*]] = load i32* %[[v8]]
265*f4a2713aSLionel Sambuc // CHECK:   %[[v10:.*]] = getelementptr inbounds i8* %[[vbptr]], i32 %[[vbase_offs]]
266*f4a2713aSLionel Sambuc // CHECK:   %[[offset:.*]] = getelementptr inbounds i8* %[[v10]], i32 %[[memptr0]]
267*f4a2713aSLionel Sambuc // CHECK:   %[[v11:.*]] = bitcast i8* %[[offset]] to i32*
268*f4a2713aSLionel Sambuc // CHECK:   %[[v12:.*]] = load i32* %[[v11]]
269*f4a2713aSLionel Sambuc // CHECK:   ret i32 %[[v12]]
270*f4a2713aSLionel Sambuc // CHECK: }
271*f4a2713aSLionel Sambuc }
272*f4a2713aSLionel Sambuc 
273*f4a2713aSLionel Sambuc int loadDataMemberPointerUnspecified(Unspecified *o, int Unspecified::*memptr) {
274*f4a2713aSLionel Sambuc   return o->*memptr;
275*f4a2713aSLionel Sambuc // Test that we can unpack this aggregate member pointer and load the member
276*f4a2713aSLionel Sambuc // data pointer.
277*f4a2713aSLionel Sambuc // CHECK: define i32 @"\01?loadDataMemberPointerUnspecified@@YAHPAUUnspecified@@PQ1@H@Z"{{.*}} {
278*f4a2713aSLionel Sambuc // CHECK:   %[[o:.*]] = load %{{.*}}** %{{.*}}, align 4
279*f4a2713aSLionel Sambuc // CHECK:   %[[memptr:.*]] = load { i32, i32, i32 }* %{{.*}}, align 4
280*f4a2713aSLionel Sambuc // CHECK:   %[[memptr0:.*]] = extractvalue { i32, i32, i32 } %[[memptr:.*]], 0
281*f4a2713aSLionel Sambuc // CHECK:   %[[memptr1:.*]] = extractvalue { i32, i32, i32 } %[[memptr:.*]], 1
282*f4a2713aSLionel Sambuc // CHECK:   %[[memptr2:.*]] = extractvalue { i32, i32, i32 } %[[memptr:.*]], 2
283*f4a2713aSLionel Sambuc // CHECK:   %[[base:.*]] = bitcast %{{.*}}* %[[o]] to i8*
284*f4a2713aSLionel Sambuc // CHECK:   %[[is_vbase:.*]] = icmp ne i32 %[[memptr2]], 0
285*f4a2713aSLionel Sambuc // CHECK:   br i1 %[[is_vbase]], label %[[vadjust:.*]], label %[[skip:.*]]
286*f4a2713aSLionel Sambuc //
287*f4a2713aSLionel Sambuc // CHECK: [[vadjust]]
288*f4a2713aSLionel Sambuc // CHECK:   %[[vbptr:.*]] = getelementptr inbounds i8* %[[base]], i32 %[[memptr1]]
289*f4a2713aSLionel Sambuc // CHECK:   %[[vbptr_a:.*]] = bitcast i8* %[[vbptr]] to i8**
290*f4a2713aSLionel Sambuc // CHECK:   %[[vbtable:.*]] = load i8** %[[vbptr_a:.*]]
291*f4a2713aSLionel Sambuc // CHECK:   %[[v7:.*]] = getelementptr inbounds i8* %[[vbtable]], i32 %[[memptr2]]
292*f4a2713aSLionel Sambuc // CHECK:   %[[v8:.*]] = bitcast i8* %[[v7]] to i32*
293*f4a2713aSLionel Sambuc // CHECK:   %[[vbase_offs:.*]] = load i32* %[[v8]]
294*f4a2713aSLionel Sambuc // CHECK:   %[[base_adj:.*]] = getelementptr inbounds i8* %[[vbptr]], i32 %[[vbase_offs]]
295*f4a2713aSLionel Sambuc //
296*f4a2713aSLionel Sambuc // CHECK: [[skip]]
297*f4a2713aSLionel Sambuc // CHECK:   %[[new_base:.*]] = phi i8* [ %[[base]], %{{.*}} ], [ %[[base_adj]], %[[vadjust]] ]
298*f4a2713aSLionel Sambuc // CHECK:   %[[offset:.*]] = getelementptr inbounds i8* %[[new_base]], i32 %[[memptr0]]
299*f4a2713aSLionel Sambuc // CHECK:   %[[v11:.*]] = bitcast i8* %[[offset]] to i32*
300*f4a2713aSLionel Sambuc // CHECK:   %[[v12:.*]] = load i32* %[[v11]]
301*f4a2713aSLionel Sambuc // CHECK:   ret i32 %[[v12]]
302*f4a2713aSLionel Sambuc // CHECK: }
303*f4a2713aSLionel Sambuc }
304*f4a2713aSLionel Sambuc 
305*f4a2713aSLionel Sambuc void callMemberPointerSingle(Single *o, void (Single::*memptr)()) {
306*f4a2713aSLionel Sambuc   (o->*memptr)();
307*f4a2713aSLionel Sambuc // Just look for an indirect thiscall.
308*f4a2713aSLionel Sambuc // CHECK: define void @"\01?callMemberPointerSingle@@{{.*}} {{.*}} {
309*f4a2713aSLionel Sambuc // CHECK:   call x86_thiscallcc void %{{.*}}(%{{.*}} %{{.*}})
310*f4a2713aSLionel Sambuc // CHECK:   ret void
311*f4a2713aSLionel Sambuc // CHECK: }
312*f4a2713aSLionel Sambuc }
313*f4a2713aSLionel Sambuc 
314*f4a2713aSLionel Sambuc void callMemberPointerMultiple(Multiple *o, void (Multiple::*memptr)()) {
315*f4a2713aSLionel Sambuc   (o->*memptr)();
316*f4a2713aSLionel Sambuc // CHECK: define void @"\01?callMemberPointerMultiple@@{{.*}} {
317*f4a2713aSLionel Sambuc // CHECK:   %[[memptr0:.*]] = extractvalue { i8*, i32 } %{{.*}}, 0
318*f4a2713aSLionel Sambuc // CHECK:   %[[memptr1:.*]] = extractvalue { i8*, i32 } %{{.*}}, 1
319*f4a2713aSLionel Sambuc // CHECK:   %[[this_adjusted:.*]] = getelementptr inbounds i8* %{{.*}}, i32 %[[memptr1]]
320*f4a2713aSLionel Sambuc // CHECK:   %[[this:.*]] = bitcast i8* %[[this_adjusted]] to {{.*}}
321*f4a2713aSLionel Sambuc // CHECK:   %[[fptr:.*]] = bitcast i8* %[[memptr0]] to {{.*}}
322*f4a2713aSLionel Sambuc // CHECK:   call x86_thiscallcc void %[[fptr]](%{{.*}} %[[this]])
323*f4a2713aSLionel Sambuc // CHECK:   ret void
324*f4a2713aSLionel Sambuc // CHECK: }
325*f4a2713aSLionel Sambuc }
326*f4a2713aSLionel Sambuc 
327*f4a2713aSLionel Sambuc void callMemberPointerVirtualBase(Virtual *o, void (Virtual::*memptr)()) {
328*f4a2713aSLionel Sambuc   (o->*memptr)();
329*f4a2713aSLionel Sambuc // This shares a lot with virtual data member pointers.
330*f4a2713aSLionel Sambuc // CHECK: define void @"\01?callMemberPointerVirtualBase@@{{.*}} {
331*f4a2713aSLionel Sambuc // CHECK:   %[[memptr0:.*]] = extractvalue { i8*, i32, i32 } %{{.*}}, 0
332*f4a2713aSLionel Sambuc // CHECK:   %[[memptr1:.*]] = extractvalue { i8*, i32, i32 } %{{.*}}, 1
333*f4a2713aSLionel Sambuc // CHECK:   %[[memptr2:.*]] = extractvalue { i8*, i32, i32 } %{{.*}}, 2
334*f4a2713aSLionel Sambuc // CHECK:   %[[vbptr:.*]] = getelementptr inbounds i8* %{{.*}}, i32 0
335*f4a2713aSLionel Sambuc // CHECK:   %[[vbptr_a:.*]] = bitcast i8* %[[vbptr]] to i8**
336*f4a2713aSLionel Sambuc // CHECK:   %[[vbtable:.*]] = load i8** %[[vbptr_a:.*]]
337*f4a2713aSLionel Sambuc // CHECK:   %[[v7:.*]] = getelementptr inbounds i8* %[[vbtable]], i32 %[[memptr2]]
338*f4a2713aSLionel Sambuc // CHECK:   %[[v8:.*]] = bitcast i8* %[[v7]] to i32*
339*f4a2713aSLionel Sambuc // CHECK:   %[[vbase_offs:.*]] = load i32* %[[v8]]
340*f4a2713aSLionel Sambuc // CHECK:   %[[v10:.*]] = getelementptr inbounds i8* %[[vbptr]], i32 %[[vbase_offs]]
341*f4a2713aSLionel Sambuc // CHECK:   %[[this_adjusted:.*]] = getelementptr inbounds i8* %[[v10]], i32 %[[memptr1]]
342*f4a2713aSLionel Sambuc // CHECK:   %[[fptr:.*]] = bitcast i8* %[[memptr0]] to void ({{.*}})
343*f4a2713aSLionel Sambuc // CHECK:   %[[this:.*]] = bitcast i8* %[[this_adjusted]] to {{.*}}
344*f4a2713aSLionel Sambuc // CHECK:   call x86_thiscallcc void %[[fptr]](%{{.*}} %[[this]])
345*f4a2713aSLionel Sambuc // CHECK:   ret void
346*f4a2713aSLionel Sambuc // CHECK: }
347*f4a2713aSLionel Sambuc }
348*f4a2713aSLionel Sambuc 
349*f4a2713aSLionel Sambuc bool compareSingleFunctionMemptr(void (Single::*l)(), void (Single::*r)()) {
350*f4a2713aSLionel Sambuc   return l == r;
351*f4a2713aSLionel Sambuc // Should only be one comparison here.
352*f4a2713aSLionel Sambuc // CHECK: define zeroext i1 @"\01?compareSingleFunctionMemptr@@YA_NP8Single@@AEXXZ0@Z"{{.*}} {
353*f4a2713aSLionel Sambuc // CHECK-NOT: icmp
354*f4a2713aSLionel Sambuc // CHECK:   %[[r:.*]] = icmp eq
355*f4a2713aSLionel Sambuc // CHECK-NOT: icmp
356*f4a2713aSLionel Sambuc // CHECK:   ret i1 %[[r]]
357*f4a2713aSLionel Sambuc // CHECK: }
358*f4a2713aSLionel Sambuc }
359*f4a2713aSLionel Sambuc 
360*f4a2713aSLionel Sambuc bool compareNeqSingleFunctionMemptr(void (Single::*l)(), void (Single::*r)()) {
361*f4a2713aSLionel Sambuc   return l != r;
362*f4a2713aSLionel Sambuc // Should only be one comparison here.
363*f4a2713aSLionel Sambuc // CHECK: define zeroext i1 @"\01?compareNeqSingleFunctionMemptr@@YA_NP8Single@@AEXXZ0@Z"{{.*}} {
364*f4a2713aSLionel Sambuc // CHECK-NOT: icmp
365*f4a2713aSLionel Sambuc // CHECK:   %[[r:.*]] = icmp ne
366*f4a2713aSLionel Sambuc // CHECK-NOT: icmp
367*f4a2713aSLionel Sambuc // CHECK:   ret i1 %[[r]]
368*f4a2713aSLionel Sambuc // CHECK: }
369*f4a2713aSLionel Sambuc }
370*f4a2713aSLionel Sambuc 
371*f4a2713aSLionel Sambuc bool unspecFuncMemptrEq(void (Unspecified::*l)(), void (Unspecified::*r)()) {
372*f4a2713aSLionel Sambuc   return l == r;
373*f4a2713aSLionel Sambuc // CHECK: define zeroext i1 @"\01?unspecFuncMemptrEq@@YA_NP8Unspecified@@AEXXZ0@Z"{{.*}} {
374*f4a2713aSLionel Sambuc // CHECK:   %[[lhs0:.*]] = extractvalue { i8*, i32, i32, i32 } %[[l:.*]], 0
375*f4a2713aSLionel Sambuc // CHECK:   %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[r:.*]], 0
376*f4a2713aSLionel Sambuc // CHECK:   %[[cmp0:.*]] = icmp eq i8* %[[lhs0]], %{{.*}}
377*f4a2713aSLionel Sambuc // CHECK:   %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[l]], 1
378*f4a2713aSLionel Sambuc // CHECK:   %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[r]], 1
379*f4a2713aSLionel Sambuc // CHECK:   %[[cmp1:.*]] = icmp eq i32
380*f4a2713aSLionel Sambuc // CHECK:   %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[l]], 2
381*f4a2713aSLionel Sambuc // CHECK:   %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[r]], 2
382*f4a2713aSLionel Sambuc // CHECK:   %[[cmp2:.*]] = icmp eq i32
383*f4a2713aSLionel Sambuc // CHECK:   %[[res12:.*]] = and i1 %[[cmp1]], %[[cmp2]]
384*f4a2713aSLionel Sambuc // CHECK:   %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[l]], 3
385*f4a2713aSLionel Sambuc // CHECK:   %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[r]], 3
386*f4a2713aSLionel Sambuc // CHECK:   %[[cmp3:.*]] = icmp eq i32
387*f4a2713aSLionel Sambuc // CHECK:   %[[res123:.*]] = and i1 %[[res12]], %[[cmp3]]
388*f4a2713aSLionel Sambuc // CHECK:   %[[iszero:.*]] = icmp eq i8* %[[lhs0]], null
389*f4a2713aSLionel Sambuc // CHECK:   %[[bits_or_null:.*]] = or i1 %[[res123]], %[[iszero]]
390*f4a2713aSLionel Sambuc // CHECK:   %{{.*}} = and i1 %[[bits_or_null]], %[[cmp0]]
391*f4a2713aSLionel Sambuc // CHECK:   ret i1 %{{.*}}
392*f4a2713aSLionel Sambuc // CHECK: }
393*f4a2713aSLionel Sambuc }
394*f4a2713aSLionel Sambuc 
395*f4a2713aSLionel Sambuc bool unspecFuncMemptrNeq(void (Unspecified::*l)(), void (Unspecified::*r)()) {
396*f4a2713aSLionel Sambuc   return l != r;
397*f4a2713aSLionel Sambuc // CHECK: define zeroext i1 @"\01?unspecFuncMemptrNeq@@YA_NP8Unspecified@@AEXXZ0@Z"{{.*}} {
398*f4a2713aSLionel Sambuc // CHECK:   %[[lhs0:.*]] = extractvalue { i8*, i32, i32, i32 } %[[l:.*]], 0
399*f4a2713aSLionel Sambuc // CHECK:   %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[r:.*]], 0
400*f4a2713aSLionel Sambuc // CHECK:   %[[cmp0:.*]] = icmp ne i8* %[[lhs0]], %{{.*}}
401*f4a2713aSLionel Sambuc // CHECK:   %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[l]], 1
402*f4a2713aSLionel Sambuc // CHECK:   %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[r]], 1
403*f4a2713aSLionel Sambuc // CHECK:   %[[cmp1:.*]] = icmp ne i32
404*f4a2713aSLionel Sambuc // CHECK:   %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[l]], 2
405*f4a2713aSLionel Sambuc // CHECK:   %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[r]], 2
406*f4a2713aSLionel Sambuc // CHECK:   %[[cmp2:.*]] = icmp ne i32
407*f4a2713aSLionel Sambuc // CHECK:   %[[res12:.*]] = or i1 %[[cmp1]], %[[cmp2]]
408*f4a2713aSLionel Sambuc // CHECK:   %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[l]], 3
409*f4a2713aSLionel Sambuc // CHECK:   %{{.*}} = extractvalue { i8*, i32, i32, i32 } %[[r]], 3
410*f4a2713aSLionel Sambuc // CHECK:   %[[cmp3:.*]] = icmp ne i32
411*f4a2713aSLionel Sambuc // CHECK:   %[[res123:.*]] = or i1 %[[res12]], %[[cmp3]]
412*f4a2713aSLionel Sambuc // CHECK:   %[[iszero:.*]] = icmp ne i8* %[[lhs0]], null
413*f4a2713aSLionel Sambuc // CHECK:   %[[bits_or_null:.*]] = and i1 %[[res123]], %[[iszero]]
414*f4a2713aSLionel Sambuc // CHECK:   %{{.*}} = or i1 %[[bits_or_null]], %[[cmp0]]
415*f4a2713aSLionel Sambuc // CHECK:   ret i1 %{{.*}}
416*f4a2713aSLionel Sambuc // CHECK: }
417*f4a2713aSLionel Sambuc }
418*f4a2713aSLionel Sambuc 
419*f4a2713aSLionel Sambuc bool unspecDataMemptrEq(int Unspecified::*l, int Unspecified::*r) {
420*f4a2713aSLionel Sambuc   return l == r;
421*f4a2713aSLionel Sambuc // CHECK: define zeroext i1 @"\01?unspecDataMemptrEq@@YA_NPQUnspecified@@H0@Z"{{.*}} {
422*f4a2713aSLionel Sambuc // CHECK:   extractvalue { i32, i32, i32 } %{{.*}}, 0
423*f4a2713aSLionel Sambuc // CHECK:   extractvalue { i32, i32, i32 } %{{.*}}, 0
424*f4a2713aSLionel Sambuc // CHECK:   icmp eq i32
425*f4a2713aSLionel Sambuc // CHECK:   extractvalue { i32, i32, i32 } %{{.*}}, 1
426*f4a2713aSLionel Sambuc // CHECK:   extractvalue { i32, i32, i32 } %{{.*}}, 1
427*f4a2713aSLionel Sambuc // CHECK:   icmp eq i32
428*f4a2713aSLionel Sambuc // CHECK:   extractvalue { i32, i32, i32 } %{{.*}}, 2
429*f4a2713aSLionel Sambuc // CHECK:   extractvalue { i32, i32, i32 } %{{.*}}, 2
430*f4a2713aSLionel Sambuc // CHECK:   icmp eq i32
431*f4a2713aSLionel Sambuc // CHECK:   and i1
432*f4a2713aSLionel Sambuc // CHECK:   and i1
433*f4a2713aSLionel Sambuc // CHECK:   ret i1
434*f4a2713aSLionel Sambuc // CHECK: }
435*f4a2713aSLionel Sambuc }
436*f4a2713aSLionel Sambuc 
437*f4a2713aSLionel Sambuc void (Multiple::*convertB2FuncToMultiple(void (B2::*mp)()))() {
438*f4a2713aSLionel Sambuc   return mp;
439*f4a2713aSLionel Sambuc // CHECK: define i64 @"\01?convertB2FuncToMultiple@@YAP8Multiple@@AEXXZP8B2@@AEXXZ@Z"{{.*}} {
440*f4a2713aSLionel Sambuc // CHECK:   store
441*f4a2713aSLionel Sambuc // CHECK:   %[[mp:.*]] = load i8** %{{.*}}, align 4
442*f4a2713aSLionel Sambuc // CHECK:   icmp ne i8* %[[mp]], null
443*f4a2713aSLionel Sambuc // CHECK:   br i1 %{{.*}} label %{{.*}}, label %{{.*}}
444*f4a2713aSLionel Sambuc //
445*f4a2713aSLionel Sambuc //        memptr.convert:                                   ; preds = %entry
446*f4a2713aSLionel Sambuc // CHECK:   insertvalue { i8*, i32 } undef, i8* %[[mp]], 0
447*f4a2713aSLionel Sambuc // CHECK:   insertvalue { i8*, i32 } %{{.*}}, i32 4, 1
448*f4a2713aSLionel Sambuc // CHECK:   br label
449*f4a2713aSLionel Sambuc //
450*f4a2713aSLionel Sambuc //        memptr.converted:                                 ; preds = %memptr.convert, %entry
451*f4a2713aSLionel Sambuc // CHECK:   phi { i8*, i32 } [ zeroinitializer, %{{.*}} ], [ {{.*}} ]
452*f4a2713aSLionel Sambuc // CHECK: }
453*f4a2713aSLionel Sambuc }
454*f4a2713aSLionel Sambuc 
455*f4a2713aSLionel Sambuc void (B2::*convertMultipleFuncToB2(void (Multiple::*mp)()))() {
456*f4a2713aSLionel Sambuc // FIXME: cl emits warning C4407 on this code because of the representation
457*f4a2713aSLionel Sambuc // change.  We might want to do the same.
458*f4a2713aSLionel Sambuc   return static_cast<void (B2::*)()>(mp);
459*f4a2713aSLionel Sambuc // FIXME: We should return i8* instead of i32 here.  The ptrtoint cast prevents
460*f4a2713aSLionel Sambuc // LLVM from optimizing away the branch.  This is likely a bug in
461*f4a2713aSLionel Sambuc // lib/CodeGen/TargetInfo.cpp with how we classify memptr types for returns.
462*f4a2713aSLionel Sambuc //
463*f4a2713aSLionel Sambuc // CHECK: define i32 @"\01?convertMultipleFuncToB2@@YAP8B2@@AEXXZP8Multiple@@AEXXZ@Z"{{.*}} {
464*f4a2713aSLionel Sambuc // CHECK:   store
465*f4a2713aSLionel Sambuc // CHECK:   %[[src:.*]] = load { i8*, i32 }* %{{.*}}, align 4
466*f4a2713aSLionel Sambuc // CHECK:   extractvalue { i8*, i32 } %[[src]], 0
467*f4a2713aSLionel Sambuc // CHECK:   icmp ne i8* %{{.*}}, null
468*f4a2713aSLionel Sambuc // CHECK:   br i1 %{{.*}}, label %{{.*}}, label %{{.*}}
469*f4a2713aSLionel Sambuc //
470*f4a2713aSLionel Sambuc //        memptr.convert:                                   ; preds = %entry
471*f4a2713aSLionel Sambuc // CHECK:   %[[fp:.*]] = extractvalue { i8*, i32 } %[[src]], 0
472*f4a2713aSLionel Sambuc // CHECK:   br label
473*f4a2713aSLionel Sambuc //
474*f4a2713aSLionel Sambuc //        memptr.converted:                                 ; preds = %memptr.convert, %entry
475*f4a2713aSLionel Sambuc // CHECK:   phi i8* [ null, %{{.*}} ], [ %[[fp]], %{{.*}} ]
476*f4a2713aSLionel Sambuc // CHECK: }
477*f4a2713aSLionel Sambuc }
478*f4a2713aSLionel Sambuc 
479*f4a2713aSLionel Sambuc namespace Test1 {
480*f4a2713aSLionel Sambuc 
481*f4a2713aSLionel Sambuc struct A { int a; };
482*f4a2713aSLionel Sambuc struct B { int b; };
483*f4a2713aSLionel Sambuc struct C : virtual A { int c; };
484*f4a2713aSLionel Sambuc struct D : B, C { int d; };
485*f4a2713aSLionel Sambuc 
486*f4a2713aSLionel Sambuc void (D::*convertCToD(void (C::*mp)()))() {
487*f4a2713aSLionel Sambuc   return mp;
488*f4a2713aSLionel Sambuc // CHECK: define void @"\01?convertCToD@Test1@@YAP8D@1@AEXXZP8C@1@AEXXZ@Z"{{.*}} {
489*f4a2713aSLionel Sambuc // CHECK:   store
490*f4a2713aSLionel Sambuc // CHECK:   load { i8*, i32, i32 }* %{{.*}}, align 4
491*f4a2713aSLionel Sambuc // CHECK:   extractvalue { i8*, i32, i32 } %{{.*}}, 0
492*f4a2713aSLionel Sambuc // CHECK:   icmp ne i8* %{{.*}}, null
493*f4a2713aSLionel Sambuc // CHECK:   br i1 %{{.*}}, label %{{.*}}, label %{{.*}}
494*f4a2713aSLionel Sambuc //
495*f4a2713aSLionel Sambuc //        memptr.convert:                                   ; preds = %entry
496*f4a2713aSLionel Sambuc // CHECK:   extractvalue { i8*, i32, i32 } %{{.*}}, 0
497*f4a2713aSLionel Sambuc // CHECK:   extractvalue { i8*, i32, i32 } %{{.*}}, 1
498*f4a2713aSLionel Sambuc // CHECK:   extractvalue { i8*, i32, i32 } %{{.*}}, 2
499*f4a2713aSLionel Sambuc // CHECK:   %[[adj:.*]] = add nsw i32 %{{.*}}, 4
500*f4a2713aSLionel Sambuc // CHECK:   insertvalue { i8*, i32, i32 } undef, i8* {{.*}}, 0
501*f4a2713aSLionel Sambuc // CHECK:   insertvalue { i8*, i32, i32 } {{.*}}, i32 %[[adj]], 1
502*f4a2713aSLionel Sambuc // CHECK:   insertvalue { i8*, i32, i32 } {{.*}}, i32 {{.*}}, 2
503*f4a2713aSLionel Sambuc // CHECK:   br label
504*f4a2713aSLionel Sambuc //
505*f4a2713aSLionel Sambuc //        memptr.converted:                                 ; preds = %memptr.convert, %entry
506*f4a2713aSLionel Sambuc // CHECK:   phi { i8*, i32, i32 } [ { i8* null, i32 0, i32 -1 }, {{.*}} ], [ {{.*}} ]
507*f4a2713aSLionel Sambuc // CHECK: }
508*f4a2713aSLionel Sambuc }
509*f4a2713aSLionel Sambuc 
510*f4a2713aSLionel Sambuc }
511*f4a2713aSLionel Sambuc 
512*f4a2713aSLionel Sambuc namespace Test2 {
513*f4a2713aSLionel Sambuc // Test that we dynamically convert between different null reps.
514*f4a2713aSLionel Sambuc 
515*f4a2713aSLionel Sambuc struct A { int a; };
516*f4a2713aSLionel Sambuc struct B : A { int b; };
517*f4a2713aSLionel Sambuc struct C : A {
518*f4a2713aSLionel Sambuc   int c;
519*f4a2713aSLionel Sambuc   virtual void hasVfPtr();
520*f4a2713aSLionel Sambuc };
521*f4a2713aSLionel Sambuc 
522*f4a2713aSLionel Sambuc int A::*reinterpret(int B::*mp) {
523*f4a2713aSLionel Sambuc   return reinterpret_cast<int A::*>(mp);
524*f4a2713aSLionel Sambuc // CHECK: define i32 @"\01?reinterpret@Test2@@YAPQA@1@HPQB@1@H@Z"{{.*}}  {
525*f4a2713aSLionel Sambuc // CHECK-NOT: select
526*f4a2713aSLionel Sambuc // CHECK:   ret i32
527*f4a2713aSLionel Sambuc // CHECK: }
528*f4a2713aSLionel Sambuc }
529*f4a2713aSLionel Sambuc 
530*f4a2713aSLionel Sambuc int A::*reinterpret(int C::*mp) {
531*f4a2713aSLionel Sambuc   return reinterpret_cast<int A::*>(mp);
532*f4a2713aSLionel Sambuc // CHECK: define i32 @"\01?reinterpret@Test2@@YAPQA@1@HPQC@1@H@Z"{{.*}}  {
533*f4a2713aSLionel Sambuc // CHECK:   %[[mp:.*]] = load i32*
534*f4a2713aSLionel Sambuc // CHECK:   %[[cmp:.*]] = icmp ne i32 %[[mp]], 0
535*f4a2713aSLionel Sambuc // CHECK:   select i1 %[[cmp]], i32 %[[mp]], i32 -1
536*f4a2713aSLionel Sambuc // CHECK: }
537*f4a2713aSLionel Sambuc }
538*f4a2713aSLionel Sambuc 
539*f4a2713aSLionel Sambuc }
540