blob: f6f75835c658e6840e240f6eb0e13d7b8dd8ef9a [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);
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -070021 virtual void thud(...);
Hans Wennborg93b717a2013-11-15 17:24:45 +000022};
23
24namespace {
25struct D {
26 virtual void foo();
27};
28}
29
30void f() {
31 void (C::*ptr)();
32 ptr = &C::foo;
33 ptr = &C::foo; // Don't crash trying to define the thunk twice :)
34
35 int (C::*ptr2)(int, double);
36 ptr2 = &C::bar;
37
38 S (C::*ptr3)(int);
39 ptr3 = &C::baz;
40
41 void (D::*ptr4)();
42 ptr4 = &D::foo;
43
Stephen Hines6bcf27b2014-05-29 04:14:42 -070044 S (C::*ptr5)(U);
45 ptr5 = &C::qux;
46
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -070047 void (C::*ptr6)(...);
48 ptr6 = &C::thud;
49
Stephen Hines6bcf27b2014-05-29 04:14:42 -070050
Hans Wennborg93b717a2013-11-15 17:24:45 +000051// CHECK32-LABEL: define void @"\01?f@@YAXXZ"()
Stephen Hines176edba2014-12-01 14:53:08 -080052// CHECK32: store i8* bitcast (void (%struct.C*, ...)* @"\01??_9C@@$BA@AE" to i8*), i8** %ptr
53// CHECK32: store i8* bitcast (void (%struct.C*, ...)* @"\01??_9C@@$B3AE" to i8*), i8** %ptr2
54// CHECK32: store i8* bitcast (void (%struct.C*, ...)* @"\01??_9C@@$B7AE" to i8*), i8** %ptr3
55// 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 +000056// CHECK32: }
57//
58// CHECK64-LABEL: define void @"\01?f@@YAXXZ"()
Stephen Hines176edba2014-12-01 14:53:08 -080059// CHECK64: store i8* bitcast (void (%struct.C*, ...)* @"\01??_9C@@$BA@AA" to i8*), i8** %ptr
60// CHECK64: store i8* bitcast (void (%struct.C*, ...)* @"\01??_9C@@$B7AA" to i8*), i8** %ptr2
61// CHECK64: store i8* bitcast (void (%struct.C*, ...)* @"\01??_9C@@$BBA@AA" to i8*), i8** %ptr3
62// 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 +000063// CHECK64: }
64}
65
66
67// Thunk for calling the 1st virtual function in C with no parameters.
Stephen Hines176edba2014-12-01 14:53:08 -080068// CHECK32-LABEL: define linkonce_odr x86_thiscallcc void @"\01??_9C@@$BA@AE"(%struct.C* %this, ...)
Stephen Hines0e2c34f2015-03-23 12:09:02 -070069// CHECK32: #[[ATTR:[0-9]+]]
Stephen Hines176edba2014-12-01 14:53:08 -080070// CHECK32-NOT: unnamed_addr
Stephen Hines0e2c34f2015-03-23 12:09:02 -070071// CHECK32: comdat
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -070072// CHECK32: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)*, void (%struct.C*, ...)** %{{.*}}, i64 0
73// CHECK32: [[CALLEE:%.*]] = load void (%struct.C*, ...)*, void (%struct.C*, ...)** [[VPTR]]
Pirama Arumuga Nainar33337ca2015-05-06 11:48:57 -070074// CHECK32: musttail call x86_thiscallcc void (%struct.C*, ...) [[CALLEE]](%struct.C* %{{.*}}, ...)
Stephen Hines176edba2014-12-01 14:53:08 -080075// CHECK32-NEXT: ret void
Hans Wennborg93b717a2013-11-15 17:24:45 +000076// CHECK32: }
77//
Stephen Hines176edba2014-12-01 14:53:08 -080078// CHECK64-LABEL: define linkonce_odr void @"\01??_9C@@$BA@AA"(%struct.C* %this, ...)
Stephen Hines0e2c34f2015-03-23 12:09:02 -070079// CHECK64: #[[ATTR:[0-9]+]]
Stephen Hines176edba2014-12-01 14:53:08 -080080// CHECK64-NOT: unnamed_addr
Stephen Hines0e2c34f2015-03-23 12:09:02 -070081// CHECK64: comdat
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -070082// CHECK64: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)*, void (%struct.C*, ...)** %{{.*}}, i64 0
83// CHECK64: [[CALLEE:%.*]] = load void (%struct.C*, ...)*, void (%struct.C*, ...)** [[VPTR]]
Pirama Arumuga Nainar33337ca2015-05-06 11:48:57 -070084// CHECK64: musttail call void (%struct.C*, ...) [[CALLEE]](%struct.C* %{{.*}}, ...)
Stephen Hines176edba2014-12-01 14:53:08 -080085// CHECK64-NEXT: ret void
Hans Wennborg93b717a2013-11-15 17:24:45 +000086// CHECK64: }
87
88// Thunk for calling the 2nd virtual function in C, taking int and double as parameters, returning int.
Stephen Hines176edba2014-12-01 14:53:08 -080089// CHECK32-LABEL: define linkonce_odr x86_thiscallcc void @"\01??_9C@@$B3AE"(%struct.C* %this, ...)
Stephen Hines0e2c34f2015-03-23 12:09:02 -070090// CHECK32: #[[ATTR]] comdat
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -070091// CHECK32: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)*, void (%struct.C*, ...)** %{{.*}}, i64 1
92// CHECK32: [[CALLEE:%.*]] = load void (%struct.C*, ...)*, void (%struct.C*, ...)** [[VPTR]]
Pirama Arumuga Nainar33337ca2015-05-06 11:48:57 -070093// CHECK32: musttail call x86_thiscallcc void (%struct.C*, ...) [[CALLEE]](%struct.C* %{{.*}}, ...)
Stephen Hines176edba2014-12-01 14:53:08 -080094// CHECK32-NEXT: ret void
Hans Wennborg93b717a2013-11-15 17:24:45 +000095// CHECK32: }
96//
Stephen Hines176edba2014-12-01 14:53:08 -080097// CHECK64-LABEL: define linkonce_odr void @"\01??_9C@@$B7AA"(%struct.C* %this, ...)
Stephen Hines0e2c34f2015-03-23 12:09:02 -070098// CHECK64: #[[ATTR]] comdat
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -070099// CHECK64: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)*, void (%struct.C*, ...)** %{{.*}}, i64 1
100// CHECK64: [[CALLEE:%.*]] = load void (%struct.C*, ...)*, void (%struct.C*, ...)** [[VPTR]]
Pirama Arumuga Nainar33337ca2015-05-06 11:48:57 -0700101// CHECK64: musttail call void (%struct.C*, ...) [[CALLEE]](%struct.C* %{{.*}}, ...)
Stephen Hines176edba2014-12-01 14:53:08 -0800102// CHECK64-NEXT: ret void
Hans Wennborg93b717a2013-11-15 17:24:45 +0000103// CHECK64: }
104
105// Thunk for calling the 3rd virtual function in C, taking an int parameter, returning a struct.
Stephen Hines176edba2014-12-01 14:53:08 -0800106// CHECK32-LABEL: define linkonce_odr x86_thiscallcc void @"\01??_9C@@$B7AE"(%struct.C* %this, ...)
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700107// CHECK32: #[[ATTR]] comdat
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -0700108// CHECK32: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)*, void (%struct.C*, ...)** %{{.*}}, i64 2
109// CHECK32: [[CALLEE:%.*]] = load void (%struct.C*, ...)*, void (%struct.C*, ...)** [[VPTR]]
Pirama Arumuga Nainar33337ca2015-05-06 11:48:57 -0700110// CHECK32: musttail call x86_thiscallcc void (%struct.C*, ...) [[CALLEE]](%struct.C* %{{.*}}, ...)
Stephen Hines176edba2014-12-01 14:53:08 -0800111// CHECK32-NEXT: ret void
Hans Wennborg93b717a2013-11-15 17:24:45 +0000112// CHECK32: }
113//
Stephen Hines176edba2014-12-01 14:53:08 -0800114// CHECK64-LABEL: define linkonce_odr void @"\01??_9C@@$BBA@AA"(%struct.C* %this, ...)
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700115// CHECK64: #[[ATTR]] comdat
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -0700116// CHECK64: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)*, void (%struct.C*, ...)** %{{.*}}, i64 2
117// CHECK64: [[CALLEE:%.*]] = load void (%struct.C*, ...)*, void (%struct.C*, ...)** [[VPTR]]
Pirama Arumuga Nainar33337ca2015-05-06 11:48:57 -0700118// CHECK64: musttail call void (%struct.C*, ...) [[CALLEE]](%struct.C* %{{.*}}, ...)
Stephen Hines176edba2014-12-01 14:53:08 -0800119// CHECK64-NEXT: ret void
Hans Wennborg93b717a2013-11-15 17:24:45 +0000120// CHECK64: }
121
122// Thunk for calling the virtual function in internal class D.
Stephen Hines176edba2014-12-01 14:53:08 -0800123// CHECK32-LABEL: define internal x86_thiscallcc void @"\01??_9D@?A@@$BA@AE"(%"struct.(anonymous namespace)::D"* %this, ...)
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700124// CHECK32: #[[ATTR]]
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -0700125// CHECK32: [[VPTR:%.*]] = getelementptr inbounds void (%"struct.(anonymous namespace)::D"*, ...)*, void (%"struct.(anonymous namespace)::D"*, ...)** %{{.*}}, i64 0
126// CHECK32: [[CALLEE:%.*]] = load void (%"struct.(anonymous namespace)::D"*, ...)*, void (%"struct.(anonymous namespace)::D"*, ...)** [[VPTR]]
Pirama Arumuga Nainar33337ca2015-05-06 11:48:57 -0700127// CHECK32: musttail call x86_thiscallcc void (%"struct.(anonymous namespace)::D"*, ...) [[CALLEE]](%"struct.(anonymous namespace)::D"* %{{.*}}, ...)
Stephen Hines176edba2014-12-01 14:53:08 -0800128// CHECK32-NEXT: ret void
Hans Wennborg93b717a2013-11-15 17:24:45 +0000129// CHECK32: }
130//
Stephen Hines176edba2014-12-01 14:53:08 -0800131// CHECK64-LABEL: define internal void @"\01??_9D@?A@@$BA@AA"(%"struct.(anonymous namespace)::D"* %this, ...)
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700132// CHECK64: #[[ATTR]]
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -0700133// CHECK64: [[VPTR:%.*]] = getelementptr inbounds void (%"struct.(anonymous namespace)::D"*, ...)*, void (%"struct.(anonymous namespace)::D"*, ...)** %{{.*}}, i64 0
134// CHECK64: [[CALLEE:%.*]] = load void (%"struct.(anonymous namespace)::D"*, ...)*, void (%"struct.(anonymous namespace)::D"*, ...)** [[VPTR]]
Pirama Arumuga Nainar33337ca2015-05-06 11:48:57 -0700135// CHECK64: musttail call void (%"struct.(anonymous namespace)::D"*, ...) [[CALLEE]](%"struct.(anonymous namespace)::D"* %{{.*}}, ...)
Stephen Hines176edba2014-12-01 14:53:08 -0800136// CHECK64-NEXT: ret void
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700137// CHECK64: }
138
Stephen Hines176edba2014-12-01 14:53:08 -0800139// Thunk for calling the fourth virtual function in C, taking a struct parameter
140// and returning a struct.
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700141// CHECK32-LABEL: define linkonce_odr x86_thiscallcc void @"\01??_9C@@$BM@AE"(%struct.C* %this, ...) {{.*}} comdat
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -0700142// CHECK32: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)*, void (%struct.C*, ...)** %{{.*}}, i64 3
143// CHECK32: [[CALLEE:%.*]] = load void (%struct.C*, ...)*, void (%struct.C*, ...)** [[VPTR]]
Pirama Arumuga Nainar33337ca2015-05-06 11:48:57 -0700144// CHECK32: musttail call x86_thiscallcc void (%struct.C*, ...) [[CALLEE]](%struct.C* %{{.*}}, ...)
Stephen Hines176edba2014-12-01 14:53:08 -0800145// CHECK32-NEXT: ret void
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700146// CHECK32: }
147//
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700148// CHECK64-LABEL: define linkonce_odr void @"\01??_9C@@$BBI@AA"(%struct.C* %this, ...) {{.*}} comdat
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -0700149// CHECK64: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)*, void (%struct.C*, ...)** %{{.*}}, i64 3
150// CHECK64: [[CALLEE:%.*]] = load void (%struct.C*, ...)*, void (%struct.C*, ...)** [[VPTR]]
Pirama Arumuga Nainar33337ca2015-05-06 11:48:57 -0700151// CHECK64: musttail call void (%struct.C*, ...) [[CALLEE]](%struct.C* %{{.*}}, ...)
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -0700152// CHECK64: ret void
153// CHECK64: }
154
155// Thunk for calling the fifth virtual function in C which uses the __cdecl calling convention.
156// CHECK32-LABEL: define linkonce_odr void @"\01??_9C@@$BBA@AA"(%struct.C* %this, ...) {{.*}} comdat align 2 {
157// CHECK32: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)*, void (%struct.C*, ...)** %{{.*}}, i64 4
158// CHECK32: [[CALLEE:%.*]] = load void (%struct.C*, ...)*, void (%struct.C*, ...)** [[VPTR]]
Pirama Arumuga Nainar33337ca2015-05-06 11:48:57 -0700159// CHECK32: musttail call void (%struct.C*, ...) [[CALLEE]](%struct.C* %{{.*}}, ...)
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -0700160// CHECK32: ret void
161// CHECK32: }
162//
163// CHECK64-LABEL: define linkonce_odr void @"\01??_9C@@$BCA@AA"(%struct.C* %this, ...) {{.*}} comdat align 2 {
164// CHECK64: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)*, void (%struct.C*, ...)** %{{.*}}, i64 4
165// CHECK64: [[CALLEE:%.*]] = load void (%struct.C*, ...)*, void (%struct.C*, ...)** [[VPTR]]
Pirama Arumuga Nainar33337ca2015-05-06 11:48:57 -0700166// CHECK64: musttail call void (%struct.C*, ...) [[CALLEE]](%struct.C* %{{.*}}, ...)
Hans Wennborg93b717a2013-11-15 17:24:45 +0000167// CHECK64: ret void
168// CHECK64: }
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700169
170// CHECK32: #[[ATTR]] = {{{.*}}"thunk"{{.*}}}