blob: b5db7c7881b56d42d240fe899af012bc402e404a [file] [log] [blame]
Stephen Hines651f13c2014-04-23 16:59:28 -07001// RUN: %clang_cc1 -fno-rtti -emit-llvm -triple=i386-pc-win32 %s -o - | FileCheck %s --check-prefix=CHECK32
2// RUN: %clang_cc1 -fno-rtti -emit-llvm -triple=x86_64-pc-win32 %s -o - | FileCheck %s --check-prefix=CHECK64
Hans Wennborg93b717a2013-11-15 17:24:45 +00003
4struct S {
5 int x, y, z;
6};
7
Stephen Hines6bcf27b2014-05-29 04:14:42 -07008// U is not trivially copyable, and requires inalloca to pass by value.
9struct U {
10 int u;
11 U();
12 ~U();
13 U(const U &);
14};
15
Hans Wennborg93b717a2013-11-15 17:24:45 +000016struct C {
17 virtual void foo();
18 virtual int bar(int, double);
19 virtual S baz(int);
Stephen Hines6bcf27b2014-05-29 04:14:42 -070020 virtual S qux(U);
Hans Wennborg93b717a2013-11-15 17:24:45 +000021};
22
23namespace {
24struct D {
25 virtual void foo();
26};
27}
28
29void f() {
30 void (C::*ptr)();
31 ptr = &C::foo;
32 ptr = &C::foo; // Don't crash trying to define the thunk twice :)
33
34 int (C::*ptr2)(int, double);
35 ptr2 = &C::bar;
36
37 S (C::*ptr3)(int);
38 ptr3 = &C::baz;
39
40 void (D::*ptr4)();
41 ptr4 = &D::foo;
42
Stephen Hines6bcf27b2014-05-29 04:14:42 -070043 S (C::*ptr5)(U);
44 ptr5 = &C::qux;
45
46
Hans Wennborg93b717a2013-11-15 17:24:45 +000047// CHECK32-LABEL: define void @"\01?f@@YAXXZ"()
Stephen Hines176edba2014-12-01 14:53:08 -080048// CHECK32: store i8* bitcast (void (%struct.C*, ...)* @"\01??_9C@@$BA@AE" to i8*), i8** %ptr
49// CHECK32: store i8* bitcast (void (%struct.C*, ...)* @"\01??_9C@@$B3AE" to i8*), i8** %ptr2
50// CHECK32: store i8* bitcast (void (%struct.C*, ...)* @"\01??_9C@@$B7AE" to i8*), i8** %ptr3
51// CHECK32: store i8* bitcast (void (%"struct.(anonymous namespace)::D"*, ...)* @"\01??_9D@?A@@$BA@AE" to i8*), i8** %ptr4
Hans Wennborg93b717a2013-11-15 17:24:45 +000052// CHECK32: }
53//
54// CHECK64-LABEL: define void @"\01?f@@YAXXZ"()
Stephen Hines176edba2014-12-01 14:53:08 -080055// CHECK64: store i8* bitcast (void (%struct.C*, ...)* @"\01??_9C@@$BA@AA" to i8*), i8** %ptr
56// CHECK64: store i8* bitcast (void (%struct.C*, ...)* @"\01??_9C@@$B7AA" to i8*), i8** %ptr2
57// CHECK64: store i8* bitcast (void (%struct.C*, ...)* @"\01??_9C@@$BBA@AA" to i8*), i8** %ptr3
58// CHECK64: store i8* bitcast (void (%"struct.(anonymous namespace)::D"*, ...)* @"\01??_9D@?A@@$BA@AA" to i8*), i8** %ptr
Hans Wennborg93b717a2013-11-15 17:24:45 +000059// CHECK64: }
60}
61
62
63// Thunk for calling the 1st virtual function in C with no parameters.
Stephen Hines176edba2014-12-01 14:53:08 -080064// CHECK32-LABEL: define linkonce_odr x86_thiscallcc void @"\01??_9C@@$BA@AE"(%struct.C* %this, ...)
65// CHECK32-NOT: unnamed_addr
66// CHECK32: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)** %{{.*}}, i64 0
67// CHECK32: [[CALLEE:%.*]] = load void (%struct.C*, ...)** [[VPTR]]
68// CHECK32: musttail call x86_thiscallcc void (%struct.C*, ...)* [[CALLEE]](%struct.C* %{{.*}}, ...)
69// CHECK32-NEXT: ret void
Hans Wennborg93b717a2013-11-15 17:24:45 +000070// CHECK32: }
71//
Stephen Hines176edba2014-12-01 14:53:08 -080072// CHECK64-LABEL: define linkonce_odr void @"\01??_9C@@$BA@AA"(%struct.C* %this, ...)
73// CHECK64-NOT: unnamed_addr
74// CHECK64: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)** %{{.*}}, i64 0
75// CHECK64: [[CALLEE:%.*]] = load void (%struct.C*, ...)** [[VPTR]]
76// CHECK64: musttail call void (%struct.C*, ...)* [[CALLEE]](%struct.C* %{{.*}}, ...)
77// CHECK64-NEXT: ret void
Hans Wennborg93b717a2013-11-15 17:24:45 +000078// CHECK64: }
79
80// Thunk for calling the 2nd virtual function in C, taking int and double as parameters, returning int.
Stephen Hines176edba2014-12-01 14:53:08 -080081// CHECK32-LABEL: define linkonce_odr x86_thiscallcc void @"\01??_9C@@$B3AE"(%struct.C* %this, ...)
82// CHECK32: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)** %{{.*}}, i64 1
83// CHECK32: [[CALLEE:%.*]] = load void (%struct.C*, ...)** [[VPTR]]
84// CHECK32: musttail call x86_thiscallcc void (%struct.C*, ...)* [[CALLEE]](%struct.C* %{{.*}}, ...)
85// CHECK32-NEXT: ret void
Hans Wennborg93b717a2013-11-15 17:24:45 +000086// CHECK32: }
87//
Stephen Hines176edba2014-12-01 14:53:08 -080088// CHECK64-LABEL: define linkonce_odr void @"\01??_9C@@$B7AA"(%struct.C* %this, ...)
89// CHECK64: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)** %{{.*}}, i64 1
90// CHECK64: [[CALLEE:%.*]] = load void (%struct.C*, ...)** [[VPTR]]
91// CHECK64: musttail call void (%struct.C*, ...)* [[CALLEE]](%struct.C* %{{.*}}, ...)
92// CHECK64-NEXT: ret void
Hans Wennborg93b717a2013-11-15 17:24:45 +000093// CHECK64: }
94
95// Thunk for calling the 3rd virtual function in C, taking an int parameter, returning a struct.
Stephen Hines176edba2014-12-01 14:53:08 -080096// CHECK32-LABEL: define linkonce_odr x86_thiscallcc void @"\01??_9C@@$B7AE"(%struct.C* %this, ...)
97// CHECK32: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)** %{{.*}}, i64 2
98// CHECK32: [[CALLEE:%.*]] = load void (%struct.C*, ...)** [[VPTR]]
99// CHECK32: musttail call x86_thiscallcc void (%struct.C*, ...)* [[CALLEE]](%struct.C* %{{.*}}, ...)
100// CHECK32-NEXT: ret void
Hans Wennborg93b717a2013-11-15 17:24:45 +0000101// CHECK32: }
102//
Stephen Hines176edba2014-12-01 14:53:08 -0800103// CHECK64-LABEL: define linkonce_odr void @"\01??_9C@@$BBA@AA"(%struct.C* %this, ...)
104// CHECK64: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)** %{{.*}}, i64 2
105// CHECK64: [[CALLEE:%.*]] = load void (%struct.C*, ...)** [[VPTR]]
106// CHECK64: musttail call void (%struct.C*, ...)* [[CALLEE]](%struct.C* %{{.*}}, ...)
107// CHECK64-NEXT: ret void
Hans Wennborg93b717a2013-11-15 17:24:45 +0000108// CHECK64: }
109
110// Thunk for calling the virtual function in internal class D.
Stephen Hines176edba2014-12-01 14:53:08 -0800111// CHECK32-LABEL: define internal x86_thiscallcc void @"\01??_9D@?A@@$BA@AE"(%"struct.(anonymous namespace)::D"* %this, ...)
112// CHECK32: [[VPTR:%.*]] = getelementptr inbounds void (%"struct.(anonymous namespace)::D"*, ...)** %{{.*}}, i64 0
113// CHECK32: [[CALLEE:%.*]] = load void (%"struct.(anonymous namespace)::D"*, ...)** [[VPTR]]
114// CHECK32: musttail call x86_thiscallcc void (%"struct.(anonymous namespace)::D"*, ...)* [[CALLEE]](%"struct.(anonymous namespace)::D"* %{{.*}}, ...)
115// CHECK32-NEXT: ret void
Hans Wennborg93b717a2013-11-15 17:24:45 +0000116// CHECK32: }
117//
Stephen Hines176edba2014-12-01 14:53:08 -0800118// CHECK64-LABEL: define internal void @"\01??_9D@?A@@$BA@AA"(%"struct.(anonymous namespace)::D"* %this, ...)
119// CHECK64: [[VPTR:%.*]] = getelementptr inbounds void (%"struct.(anonymous namespace)::D"*, ...)** %{{.*}}, i64 0
120// CHECK64: [[CALLEE:%.*]] = load void (%"struct.(anonymous namespace)::D"*, ...)** [[VPTR]]
121// CHECK64: musttail call void (%"struct.(anonymous namespace)::D"*, ...)* [[CALLEE]](%"struct.(anonymous namespace)::D"* %{{.*}}, ...)
122// CHECK64-NEXT: ret void
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700123// CHECK64: }
124
Stephen Hines176edba2014-12-01 14:53:08 -0800125// Thunk for calling the fourth virtual function in C, taking a struct parameter
126// and returning a struct.
127// CHECK32-LABEL: define linkonce_odr x86_thiscallcc void @"\01??_9C@@$BM@AE"(%struct.C* %this, ...)
128// CHECK32: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)** %{{.*}}, i64 3
129// CHECK32: [[CALLEE:%.*]] = load void (%struct.C*, ...)** [[VPTR]]
130// CHECK32: musttail call x86_thiscallcc void (%struct.C*, ...)* [[CALLEE]](%struct.C* %{{.*}}, ...)
131// CHECK32-NEXT: ret void
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700132// CHECK32: }
133//
Stephen Hines176edba2014-12-01 14:53:08 -0800134// CHECK64-LABEL: define linkonce_odr void @"\01??_9C@@$BBI@AA"(%struct.C* %this, ...)
135// CHECK64: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)** %{{.*}}, i64 3
136// CHECK64: [[CALLEE:%.*]] = load void (%struct.C*, ...)** [[VPTR]]
137// CHECK64: musttail call void (%struct.C*, ...)* [[CALLEE]](%struct.C* %{{.*}}, ...)
Hans Wennborg93b717a2013-11-15 17:24:45 +0000138// CHECK64: ret void
139// CHECK64: }