blob: 8f1ff36a1a8def2d1b1c55b051a62eb9465f7ab3 [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, ...)
Stephen Hines0e2c34f2015-03-23 12:09:02 -070065// CHECK32: #[[ATTR:[0-9]+]]
Stephen Hines176edba2014-12-01 14:53:08 -080066// CHECK32-NOT: unnamed_addr
Stephen Hines0e2c34f2015-03-23 12:09:02 -070067// CHECK32: comdat
Stephen Hines176edba2014-12-01 14:53:08 -080068// CHECK32: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)** %{{.*}}, i64 0
69// CHECK32: [[CALLEE:%.*]] = load void (%struct.C*, ...)** [[VPTR]]
70// CHECK32: musttail call x86_thiscallcc void (%struct.C*, ...)* [[CALLEE]](%struct.C* %{{.*}}, ...)
71// CHECK32-NEXT: ret void
Hans Wennborg93b717a2013-11-15 17:24:45 +000072// CHECK32: }
73//
Stephen Hines176edba2014-12-01 14:53:08 -080074// CHECK64-LABEL: define linkonce_odr void @"\01??_9C@@$BA@AA"(%struct.C* %this, ...)
Stephen Hines0e2c34f2015-03-23 12:09:02 -070075// CHECK64: #[[ATTR:[0-9]+]]
Stephen Hines176edba2014-12-01 14:53:08 -080076// CHECK64-NOT: unnamed_addr
Stephen Hines0e2c34f2015-03-23 12:09:02 -070077// CHECK64: comdat
Stephen Hines176edba2014-12-01 14:53:08 -080078// CHECK64: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)** %{{.*}}, i64 0
79// CHECK64: [[CALLEE:%.*]] = load void (%struct.C*, ...)** [[VPTR]]
80// CHECK64: musttail call void (%struct.C*, ...)* [[CALLEE]](%struct.C* %{{.*}}, ...)
81// CHECK64-NEXT: ret void
Hans Wennborg93b717a2013-11-15 17:24:45 +000082// CHECK64: }
83
84// Thunk for calling the 2nd virtual function in C, taking int and double as parameters, returning int.
Stephen Hines176edba2014-12-01 14:53:08 -080085// CHECK32-LABEL: define linkonce_odr x86_thiscallcc void @"\01??_9C@@$B3AE"(%struct.C* %this, ...)
Stephen Hines0e2c34f2015-03-23 12:09:02 -070086// CHECK32: #[[ATTR]] comdat
Stephen Hines176edba2014-12-01 14:53:08 -080087// CHECK32: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)** %{{.*}}, i64 1
88// CHECK32: [[CALLEE:%.*]] = load void (%struct.C*, ...)** [[VPTR]]
89// CHECK32: musttail call x86_thiscallcc void (%struct.C*, ...)* [[CALLEE]](%struct.C* %{{.*}}, ...)
90// CHECK32-NEXT: ret void
Hans Wennborg93b717a2013-11-15 17:24:45 +000091// CHECK32: }
92//
Stephen Hines176edba2014-12-01 14:53:08 -080093// CHECK64-LABEL: define linkonce_odr void @"\01??_9C@@$B7AA"(%struct.C* %this, ...)
Stephen Hines0e2c34f2015-03-23 12:09:02 -070094// CHECK64: #[[ATTR]] comdat
Stephen Hines176edba2014-12-01 14:53:08 -080095// CHECK64: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)** %{{.*}}, i64 1
96// CHECK64: [[CALLEE:%.*]] = load void (%struct.C*, ...)** [[VPTR]]
97// CHECK64: musttail call void (%struct.C*, ...)* [[CALLEE]](%struct.C* %{{.*}}, ...)
98// CHECK64-NEXT: ret void
Hans Wennborg93b717a2013-11-15 17:24:45 +000099// CHECK64: }
100
101// Thunk for calling the 3rd virtual function in C, taking an int parameter, returning a struct.
Stephen Hines176edba2014-12-01 14:53:08 -0800102// CHECK32-LABEL: define linkonce_odr x86_thiscallcc void @"\01??_9C@@$B7AE"(%struct.C* %this, ...)
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700103// CHECK32: #[[ATTR]] comdat
Stephen Hines176edba2014-12-01 14:53:08 -0800104// CHECK32: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)** %{{.*}}, i64 2
105// CHECK32: [[CALLEE:%.*]] = load void (%struct.C*, ...)** [[VPTR]]
106// CHECK32: musttail call x86_thiscallcc void (%struct.C*, ...)* [[CALLEE]](%struct.C* %{{.*}}, ...)
107// CHECK32-NEXT: ret void
Hans Wennborg93b717a2013-11-15 17:24:45 +0000108// CHECK32: }
109//
Stephen Hines176edba2014-12-01 14:53:08 -0800110// CHECK64-LABEL: define linkonce_odr void @"\01??_9C@@$BBA@AA"(%struct.C* %this, ...)
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700111// CHECK64: #[[ATTR]] comdat
Stephen Hines176edba2014-12-01 14:53:08 -0800112// CHECK64: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)** %{{.*}}, i64 2
113// CHECK64: [[CALLEE:%.*]] = load void (%struct.C*, ...)** [[VPTR]]
114// CHECK64: musttail call void (%struct.C*, ...)* [[CALLEE]](%struct.C* %{{.*}}, ...)
115// CHECK64-NEXT: ret void
Hans Wennborg93b717a2013-11-15 17:24:45 +0000116// CHECK64: }
117
118// Thunk for calling the virtual function in internal class D.
Stephen Hines176edba2014-12-01 14:53:08 -0800119// CHECK32-LABEL: define internal x86_thiscallcc void @"\01??_9D@?A@@$BA@AE"(%"struct.(anonymous namespace)::D"* %this, ...)
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700120// CHECK32: #[[ATTR]]
Stephen Hines176edba2014-12-01 14:53:08 -0800121// CHECK32: [[VPTR:%.*]] = getelementptr inbounds void (%"struct.(anonymous namespace)::D"*, ...)** %{{.*}}, i64 0
122// CHECK32: [[CALLEE:%.*]] = load void (%"struct.(anonymous namespace)::D"*, ...)** [[VPTR]]
123// CHECK32: musttail call x86_thiscallcc void (%"struct.(anonymous namespace)::D"*, ...)* [[CALLEE]](%"struct.(anonymous namespace)::D"* %{{.*}}, ...)
124// CHECK32-NEXT: ret void
Hans Wennborg93b717a2013-11-15 17:24:45 +0000125// CHECK32: }
126//
Stephen Hines176edba2014-12-01 14:53:08 -0800127// CHECK64-LABEL: define internal void @"\01??_9D@?A@@$BA@AA"(%"struct.(anonymous namespace)::D"* %this, ...)
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700128// CHECK64: #[[ATTR]]
Stephen Hines176edba2014-12-01 14:53:08 -0800129// CHECK64: [[VPTR:%.*]] = getelementptr inbounds void (%"struct.(anonymous namespace)::D"*, ...)** %{{.*}}, i64 0
130// CHECK64: [[CALLEE:%.*]] = load void (%"struct.(anonymous namespace)::D"*, ...)** [[VPTR]]
131// CHECK64: musttail call void (%"struct.(anonymous namespace)::D"*, ...)* [[CALLEE]](%"struct.(anonymous namespace)::D"* %{{.*}}, ...)
132// CHECK64-NEXT: ret void
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700133// CHECK64: }
134
Stephen Hines176edba2014-12-01 14:53:08 -0800135// Thunk for calling the fourth virtual function in C, taking a struct parameter
136// and returning a struct.
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700137// CHECK32-LABEL: define linkonce_odr x86_thiscallcc void @"\01??_9C@@$BM@AE"(%struct.C* %this, ...) {{.*}} comdat
Stephen Hines176edba2014-12-01 14:53:08 -0800138// CHECK32: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)** %{{.*}}, i64 3
139// CHECK32: [[CALLEE:%.*]] = load void (%struct.C*, ...)** [[VPTR]]
140// CHECK32: musttail call x86_thiscallcc void (%struct.C*, ...)* [[CALLEE]](%struct.C* %{{.*}}, ...)
141// CHECK32-NEXT: ret void
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700142// CHECK32: }
143//
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700144// CHECK64-LABEL: define linkonce_odr void @"\01??_9C@@$BBI@AA"(%struct.C* %this, ...) {{.*}} comdat
Stephen Hines176edba2014-12-01 14:53:08 -0800145// CHECK64: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)** %{{.*}}, i64 3
146// CHECK64: [[CALLEE:%.*]] = load void (%struct.C*, ...)** [[VPTR]]
147// CHECK64: musttail call void (%struct.C*, ...)* [[CALLEE]](%struct.C* %{{.*}}, ...)
Hans Wennborg93b717a2013-11-15 17:24:45 +0000148// CHECK64: ret void
149// CHECK64: }
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700150
151// CHECK32: #[[ATTR]] = {{{.*}}"thunk"{{.*}}}