xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/microsoft-abi-vmemptr-conflicts.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -fno-rtti -emit-llvm -triple=i386-pc-win32 %s -o - | FileCheck %s
2*0a6a1f1dSLionel Sambuc 
3*0a6a1f1dSLionel Sambuc // In each test case, we have two member pointers whose thunks have the same
4*0a6a1f1dSLionel Sambuc // vtable offset and same mangling, but their prototypes conflict.  The
5*0a6a1f1dSLionel Sambuc // arguments and return type may differ.  Therefore, we have to bitcast the
6*0a6a1f1dSLionel Sambuc // function prototype.  Unfortunately, if the return types differ, LLVM's
7*0a6a1f1dSLionel Sambuc // optimizers can get upset.
8*0a6a1f1dSLionel Sambuc 
9*0a6a1f1dSLionel Sambuc namespace num_params {
10*0a6a1f1dSLionel Sambuc struct A { virtual void a(int); };
11*0a6a1f1dSLionel Sambuc struct B { virtual void b(int, int); };
12*0a6a1f1dSLionel Sambuc struct C : A, B {
13*0a6a1f1dSLionel Sambuc   virtual void a(int);
14*0a6a1f1dSLionel Sambuc   virtual void b(int, int);
15*0a6a1f1dSLionel Sambuc };
f(C * c)16*0a6a1f1dSLionel Sambuc void f(C *c) {
17*0a6a1f1dSLionel Sambuc   (c->*(&C::a))(0);
18*0a6a1f1dSLionel Sambuc   (c->*(&C::b))(0, 0);
19*0a6a1f1dSLionel Sambuc }
20*0a6a1f1dSLionel Sambuc }
21*0a6a1f1dSLionel Sambuc 
22*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define void @"\01?f@num_params@@YAXPAUC@1@@Z"(%"struct.num_params::C"* %c)
23*0a6a1f1dSLionel Sambuc // CHECK: call x86_thiscallcc void bitcast (void (%"struct.num_params::C"*, ...)* @"\01??_9C@num_params@@$BA@AE" to void (%"struct.num_params::C"*, i32)*)(%"struct.num_params::C"* %{{.*}}, i32 0)
24*0a6a1f1dSLionel Sambuc // CHECK: call x86_thiscallcc void bitcast (void (%"struct.num_params::C"*, ...)* @"\01??_9C@num_params@@$BA@AE" to void (%"struct.num_params::C"*, i32, i32)*)(%"struct.num_params::C"* %{{.*}}, i32 0, i32 0)
25*0a6a1f1dSLionel Sambuc 
26*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define linkonce_odr x86_thiscallcc void @"\01??_9C@num_params@@$BA@AE"(%"struct.num_params::C"* %this, ...)
27*0a6a1f1dSLionel Sambuc // CHECK: musttail call x86_thiscallcc void (%"struct.num_params::C"*, ...)* %{{.*}}(%"struct.num_params::C"* %{{.*}}, ...)
28*0a6a1f1dSLionel Sambuc // CHECK-NEXT: ret void
29*0a6a1f1dSLionel Sambuc 
30*0a6a1f1dSLionel Sambuc namespace i64_return {
31*0a6a1f1dSLionel Sambuc struct A { virtual int a(); };
32*0a6a1f1dSLionel Sambuc struct B { virtual long long b(); };
33*0a6a1f1dSLionel Sambuc struct C : A, B {
34*0a6a1f1dSLionel Sambuc   virtual int a();
35*0a6a1f1dSLionel Sambuc   virtual long long b();
36*0a6a1f1dSLionel Sambuc };
f(C * c)37*0a6a1f1dSLionel Sambuc long long f(C *c) {
38*0a6a1f1dSLionel Sambuc   int x = (c->*(&C::a))();
39*0a6a1f1dSLionel Sambuc   long long y = (c->*(&C::b))();
40*0a6a1f1dSLionel Sambuc   return x + y;
41*0a6a1f1dSLionel Sambuc }
42*0a6a1f1dSLionel Sambuc }
43*0a6a1f1dSLionel Sambuc 
44*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define i64 @"\01?f@i64_return@@YA_JPAUC@1@@Z"(%"struct.i64_return::C"* %c)
45*0a6a1f1dSLionel Sambuc // CHECK: call x86_thiscallcc i32 bitcast (void (%"struct.i64_return::C"*, ...)* @"\01??_9C@i64_return@@$BA@AE" to i32 (%"struct.i64_return::C"*)*)(%"struct.i64_return::C"* %{{.*}})
46*0a6a1f1dSLionel Sambuc // CHECK: call x86_thiscallcc i64 bitcast (void (%"struct.i64_return::C"*, ...)* @"\01??_9C@i64_return@@$BA@AE" to i64 (%"struct.i64_return::C"*)*)(%"struct.i64_return::C"* %{{.*}})
47*0a6a1f1dSLionel Sambuc 
48*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define linkonce_odr x86_thiscallcc void @"\01??_9C@i64_return@@$BA@AE"(%"struct.i64_return::C"* %this, ...)
49*0a6a1f1dSLionel Sambuc // CHECK: musttail call x86_thiscallcc void (%"struct.i64_return::C"*, ...)* %{{.*}}(%"struct.i64_return::C"* %{{.*}}, ...)
50*0a6a1f1dSLionel Sambuc // CHECK-NEXT: ret void
51*0a6a1f1dSLionel Sambuc 
52*0a6a1f1dSLionel Sambuc namespace sret {
53*0a6a1f1dSLionel Sambuc struct Big { int big[32]; };
54*0a6a1f1dSLionel Sambuc struct A { virtual int a(); };
55*0a6a1f1dSLionel Sambuc struct B { virtual Big b(); };
56*0a6a1f1dSLionel Sambuc struct C : A, B {
57*0a6a1f1dSLionel Sambuc   virtual int a();
58*0a6a1f1dSLionel Sambuc   virtual Big b();
59*0a6a1f1dSLionel Sambuc };
f(C * c)60*0a6a1f1dSLionel Sambuc void f(C *c) {
61*0a6a1f1dSLionel Sambuc   (c->*(&C::a))();
62*0a6a1f1dSLionel Sambuc   Big b((c->*(&C::b))());
63*0a6a1f1dSLionel Sambuc }
64*0a6a1f1dSLionel Sambuc }
65*0a6a1f1dSLionel Sambuc 
66*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define void @"\01?f@sret@@YAXPAUC@1@@Z"(%"struct.sret::C"* %c)
67*0a6a1f1dSLionel Sambuc // CHECK: call x86_thiscallcc i32 bitcast (void (%"struct.sret::C"*, ...)* @"\01??_9C@sret@@$BA@AE" to i32 (%"struct.sret::C"*)*)(%"struct.sret::C"* %{{.*}})
68*0a6a1f1dSLionel Sambuc // CHECK: call x86_thiscallcc void bitcast (void (%"struct.sret::C"*, ...)* @"\01??_9C@sret@@$BA@AE" to void (%"struct.sret::C"*, %"struct.sret::Big"*)*)(%"struct.sret::C"* %{{.*}}, %"struct.sret::Big"* sret %{{.*}})
69*0a6a1f1dSLionel Sambuc 
70*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define linkonce_odr x86_thiscallcc void @"\01??_9C@sret@@$BA@AE"(%"struct.sret::C"* %this, ...)
71*0a6a1f1dSLionel Sambuc // CHECK: musttail call x86_thiscallcc void (%"struct.sret::C"*, ...)* %{{.*}}(%"struct.sret::C"* %{{.*}}, ...)
72*0a6a1f1dSLionel Sambuc // CHECK-NEXT: ret void
73*0a6a1f1dSLionel Sambuc 
74*0a6a1f1dSLionel Sambuc namespace cdecl_inalloca {
75*0a6a1f1dSLionel Sambuc // Fairly evil, since now we end up doing an inalloca-style call through a
76*0a6a1f1dSLionel Sambuc // thunk that doesn't use inalloca.  Hopefully the stacks line up?
77*0a6a1f1dSLionel Sambuc struct Big {
78*0a6a1f1dSLionel Sambuc   Big();
79*0a6a1f1dSLionel Sambuc   ~Big();
80*0a6a1f1dSLionel Sambuc   int big[32];
81*0a6a1f1dSLionel Sambuc };
82*0a6a1f1dSLionel Sambuc struct A { virtual void __cdecl a(); };
83*0a6a1f1dSLionel Sambuc struct B { virtual void __cdecl b(Big); };
84*0a6a1f1dSLionel Sambuc struct C : A, B {
85*0a6a1f1dSLionel Sambuc   virtual void __cdecl a();
86*0a6a1f1dSLionel Sambuc   virtual void __cdecl b(Big);
87*0a6a1f1dSLionel Sambuc };
f(C * c)88*0a6a1f1dSLionel Sambuc void f(C *c) {
89*0a6a1f1dSLionel Sambuc   Big b;
90*0a6a1f1dSLionel Sambuc   (c->*(&C::a))();
91*0a6a1f1dSLionel Sambuc   ((c->*(&C::b))(b));
92*0a6a1f1dSLionel Sambuc }
93*0a6a1f1dSLionel Sambuc }
94*0a6a1f1dSLionel Sambuc 
95*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define void @"\01?f@cdecl_inalloca@@YAXPAUC@1@@Z"(%"struct.cdecl_inalloca::C"* %c)
96*0a6a1f1dSLionel Sambuc // CHECK: call void bitcast (void (%"struct.cdecl_inalloca::C"*, ...)* @"\01??_9C@cdecl_inalloca@@$BA@AE" to void (%"struct.cdecl_inalloca::C"*)*)(%"struct.cdecl_inalloca::C"* %{{.*}})
97*0a6a1f1dSLionel Sambuc // CHECK: call void bitcast (void (%"struct.cdecl_inalloca::C"*, ...)* @"\01??_9C@cdecl_inalloca@@$BA@AE" to void (<{ %"struct.cdecl_inalloca::C"*, %"struct.cdecl_inalloca::Big" }>*)*)(<{ %"struct.cdecl_inalloca::C"*, %"struct.cdecl_inalloca::Big" }>* inalloca %{{.*}})
98*0a6a1f1dSLionel Sambuc 
99*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define linkonce_odr void @"\01??_9C@cdecl_inalloca@@$BA@AE"(%"struct.cdecl_inalloca::C"* %this, ...)
100*0a6a1f1dSLionel Sambuc // CHECK: musttail call void (%"struct.cdecl_inalloca::C"*, ...)* %{{.*}}(%"struct.cdecl_inalloca::C"* %{{.*}}, ...)
101*0a6a1f1dSLionel Sambuc // CHECK-NEXT: ret void
102