blob: 1880f045762715bf93b7df94af5d326c33adb998 [file] [log] [blame]
Hans Wennborgc9bd88e2014-01-14 19:35:09 +00001// 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 Wennborg88497d62013-11-15 17:24:45 +00003
4struct S {
5 int x, y, z;
6};
7
Reid Kleckner966abe72014-05-15 23:01:46 +00008// 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 Wennborg88497d62013-11-15 17:24:45 +000016struct C {
17 virtual void foo();
18 virtual int bar(int, double);
19 virtual S baz(int);
Reid Kleckner966abe72014-05-15 23:01:46 +000020 virtual S qux(U);
Reid Klecknerab2090d2014-07-26 01:34:32 +000021 virtual S __fastcall zed(U);
Hans Wennborg88497d62013-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
Reid Kleckner966abe72014-05-15 23:01:46 +000044 S (C::*ptr5)(U);
45 ptr5 = &C::qux;
46
Reid Klecknerab2090d2014-07-26 01:34:32 +000047 S (__fastcall C::*ptr6)(U);
48 ptr6 = &C::zed;
49
Reid Kleckner966abe72014-05-15 23:01:46 +000050
Hans Wennborg88497d62013-11-15 17:24:45 +000051// CHECK32-LABEL: define void @"\01?f@@YAXXZ"()
Reid Klecknerc3473512014-08-29 21:43:29 +000052// 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 Wennborg88497d62013-11-15 17:24:45 +000056// CHECK32: }
57//
58// CHECK64-LABEL: define void @"\01?f@@YAXXZ"()
Reid Klecknerc3473512014-08-29 21:43:29 +000059// 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 Wennborg88497d62013-11-15 17:24:45 +000063// CHECK64: }
64}
65
66
67// Thunk for calling the 1st virtual function in C with no parameters.
Reid Klecknerc3473512014-08-29 21:43:29 +000068// CHECK32-LABEL: define linkonce_odr x86_thiscallcc void @"\01??_9C@@$BA@AE"(%struct.C* %this, ...)
69// CHECK32: unnamed_addr
70// CHECK32: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)** %{{.*}}, i64 0
71// CHECK32: [[CALLEE:%.*]] = load void (%struct.C*, ...)** [[VPTR]]
72// CHECK32: musttail call x86_thiscallcc void (%struct.C*, ...)* [[CALLEE]](%struct.C* %{{.*}}, ...)
73// CHECK32-NEXT: ret void
Hans Wennborg88497d62013-11-15 17:24:45 +000074// CHECK32: }
75//
Reid Klecknerc3473512014-08-29 21:43:29 +000076// CHECK64-LABEL: define linkonce_odr void @"\01??_9C@@$BA@AA"(%struct.C* %this, ...)
77// CHECK64: unnamed_addr
78// 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 Wennborg88497d62013-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.
Reid Klecknerc3473512014-08-29 21:43:29 +000085// CHECK32-LABEL: define linkonce_odr x86_thiscallcc void @"\01??_9C@@$B3AE"(%struct.C* %this, ...)
86// CHECK32: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)** %{{.*}}, i64 1
87// CHECK32: [[CALLEE:%.*]] = load void (%struct.C*, ...)** [[VPTR]]
88// CHECK32: musttail call x86_thiscallcc void (%struct.C*, ...)* [[CALLEE]](%struct.C* %{{.*}}, ...)
89// CHECK32-NEXT: ret void
Hans Wennborg88497d62013-11-15 17:24:45 +000090// CHECK32: }
91//
Reid Klecknerc3473512014-08-29 21:43:29 +000092// CHECK64-LABEL: define linkonce_odr void @"\01??_9C@@$B7AA"(%struct.C* %this, ...)
93// CHECK64: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)** %{{.*}}, i64 1
94// CHECK64: [[CALLEE:%.*]] = load void (%struct.C*, ...)** [[VPTR]]
95// CHECK64: musttail call void (%struct.C*, ...)* [[CALLEE]](%struct.C* %{{.*}}, ...)
96// CHECK64-NEXT: ret void
Hans Wennborg88497d62013-11-15 17:24:45 +000097// CHECK64: }
98
99// Thunk for calling the 3rd virtual function in C, taking an int parameter, returning a struct.
Reid Klecknerc3473512014-08-29 21:43:29 +0000100// CHECK32-LABEL: define linkonce_odr x86_thiscallcc void @"\01??_9C@@$B7AE"(%struct.C* %this, ...)
101// CHECK32: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)** %{{.*}}, i64 2
102// CHECK32: [[CALLEE:%.*]] = load void (%struct.C*, ...)** [[VPTR]]
103// CHECK32: musttail call x86_thiscallcc void (%struct.C*, ...)* [[CALLEE]](%struct.C* %{{.*}}, ...)
104// CHECK32-NEXT: ret void
Hans Wennborg88497d62013-11-15 17:24:45 +0000105// CHECK32: }
106//
Reid Klecknerc3473512014-08-29 21:43:29 +0000107// CHECK64-LABEL: define linkonce_odr void @"\01??_9C@@$BBA@AA"(%struct.C* %this, ...)
108// CHECK64: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)** %{{.*}}, i64 2
109// CHECK64: [[CALLEE:%.*]] = load void (%struct.C*, ...)** [[VPTR]]
110// CHECK64: musttail call void (%struct.C*, ...)* [[CALLEE]](%struct.C* %{{.*}}, ...)
111// CHECK64-NEXT: ret void
Hans Wennborg88497d62013-11-15 17:24:45 +0000112// CHECK64: }
113
114// Thunk for calling the virtual function in internal class D.
Reid Klecknerc3473512014-08-29 21:43:29 +0000115// CHECK32-LABEL: define internal x86_thiscallcc void @"\01??_9D@?A@@$BA@AE"(%"struct.(anonymous namespace)::D"* %this, ...)
116// CHECK32: [[VPTR:%.*]] = getelementptr inbounds void (%"struct.(anonymous namespace)::D"*, ...)** %{{.*}}, i64 0
117// CHECK32: [[CALLEE:%.*]] = load void (%"struct.(anonymous namespace)::D"*, ...)** [[VPTR]]
118// CHECK32: musttail call x86_thiscallcc void (%"struct.(anonymous namespace)::D"*, ...)* [[CALLEE]](%"struct.(anonymous namespace)::D"* %{{.*}}, ...)
119// CHECK32-NEXT: ret void
Hans Wennborg88497d62013-11-15 17:24:45 +0000120// CHECK32: }
121//
Reid Klecknerc3473512014-08-29 21:43:29 +0000122// CHECK64-LABEL: define internal void @"\01??_9D@?A@@$BA@AA"(%"struct.(anonymous namespace)::D"* %this, ...)
123// CHECK64: [[VPTR:%.*]] = getelementptr inbounds void (%"struct.(anonymous namespace)::D"*, ...)** %{{.*}}, i64 0
124// CHECK64: [[CALLEE:%.*]] = load void (%"struct.(anonymous namespace)::D"*, ...)** [[VPTR]]
125// CHECK64: musttail call void (%"struct.(anonymous namespace)::D"*, ...)* [[CALLEE]](%"struct.(anonymous namespace)::D"* %{{.*}}, ...)
126// CHECK64-NEXT: ret void
Reid Kleckner966abe72014-05-15 23:01:46 +0000127// CHECK64: }
128
Reid Klecknerab2090d2014-07-26 01:34:32 +0000129// Thunk for calling the fourth virtual function in C, taking a struct parameter
130// and returning a struct.
Reid Klecknerc3473512014-08-29 21:43:29 +0000131// CHECK32-LABEL: define linkonce_odr x86_thiscallcc void @"\01??_9C@@$BM@AE"(%struct.C* %this, ...)
132// CHECK32: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)** %{{.*}}, i64 3
133// CHECK32: [[CALLEE:%.*]] = load void (%struct.C*, ...)** [[VPTR]]
134// CHECK32: musttail call x86_thiscallcc void (%struct.C*, ...)* [[CALLEE]](%struct.C* %{{.*}}, ...)
135// CHECK32-NEXT: ret void
Reid Kleckner966abe72014-05-15 23:01:46 +0000136// CHECK32: }
137//
Reid Klecknerc3473512014-08-29 21:43:29 +0000138// CHECK64-LABEL: define linkonce_odr void @"\01??_9C@@$BBI@AA"(%struct.C* %this, ...)
139// CHECK64: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)** %{{.*}}, i64 3
140// CHECK64: [[CALLEE:%.*]] = load void (%struct.C*, ...)** [[VPTR]]
141// CHECK64: musttail call void (%struct.C*, ...)* [[CALLEE]](%struct.C* %{{.*}}, ...)
Reid Klecknerab2090d2014-07-26 01:34:32 +0000142// CHECK64: ret void
143// CHECK64: }
144
145// Thunk for calling the fifth virtual function in C, taking a struct parameter
146// and returning a struct.
Reid Klecknerc3473512014-08-29 21:43:29 +0000147// CHECK32-LABEL: define linkonce_odr x86_fastcallcc void @"\01??_9C@@$BBA@AE"(%struct.C* inreg %this, ...)
148// CHECK32: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)** %{{.*}}, i64 4
149// CHECK32: [[CALLEE:%.*]] = load void (%struct.C*, ...)** [[VPTR]]
150// CHECK32: musttail call x86_fastcallcc void (%struct.C*, ...)* [[CALLEE]](%struct.C* inreg %{{.*}}, ...)
Reid Klecknerab2090d2014-07-26 01:34:32 +0000151// CHECK32-NEXT: ret void
152// CHECK32: }
153//
Reid Klecknerc3473512014-08-29 21:43:29 +0000154// CHECK64-LABEL: define linkonce_odr void @"\01??_9C@@$BCA@AA"(%struct.C* %this, ...)
155// CHECK64: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)** %{{.*}}, i64 4
156// CHECK64: [[CALLEE:%.*]] = load void (%struct.C*, ...)** [[VPTR]]
157// CHECK64: musttail call void (%struct.C*, ...)* [[CALLEE]](%struct.C* %{{.*}}, ...)
Hans Wennborg88497d62013-11-15 17:24:45 +0000158// CHECK64: ret void
159// CHECK64: }