blob: 8462c2980375041e759ecd4d2c338dc8310f9ba7 [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);
Hans Wennborg88497d62013-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
Reid Kleckner966abe72014-05-15 23:01:46 +000043 S (C::*ptr5)(U);
44 ptr5 = &C::qux;
45
46
Hans Wennborg88497d62013-11-15 17:24:45 +000047// CHECK32-LABEL: define void @"\01?f@@YAXXZ"()
Reid Klecknerc3473512014-08-29 21:43:29 +000048// 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 Wennborg88497d62013-11-15 17:24:45 +000052// CHECK32: }
53//
54// CHECK64-LABEL: define void @"\01?f@@YAXXZ"()
Reid Klecknerc3473512014-08-29 21:43:29 +000055// 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 Wennborg88497d62013-11-15 17:24:45 +000059// CHECK64: }
60}
61
62
63// Thunk for calling the 1st virtual function in C with no parameters.
Reid Klecknerc3473512014-08-29 21:43:29 +000064// CHECK32-LABEL: define linkonce_odr x86_thiscallcc void @"\01??_9C@@$BA@AE"(%struct.C* %this, ...)
Reid Kleckner76176f22014-08-29 22:06:20 +000065// CHECK32-NOT: unnamed_addr
David Majnemer8c9cdb62015-01-21 01:21:31 +000066// CHECK32: comdat
Reid Klecknerc3473512014-08-29 21:43:29 +000067// CHECK32: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)** %{{.*}}, i64 0
68// CHECK32: [[CALLEE:%.*]] = load void (%struct.C*, ...)** [[VPTR]]
69// CHECK32: musttail call x86_thiscallcc void (%struct.C*, ...)* [[CALLEE]](%struct.C* %{{.*}}, ...)
70// CHECK32-NEXT: ret void
Hans Wennborg88497d62013-11-15 17:24:45 +000071// CHECK32: }
72//
Reid Klecknerc3473512014-08-29 21:43:29 +000073// CHECK64-LABEL: define linkonce_odr void @"\01??_9C@@$BA@AA"(%struct.C* %this, ...)
Reid Kleckner76176f22014-08-29 22:06:20 +000074// CHECK64-NOT: unnamed_addr
David Majnemer8c9cdb62015-01-21 01:21:31 +000075// CHECK64: comdat
Reid Klecknerc3473512014-08-29 21:43:29 +000076// CHECK64: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)** %{{.*}}, i64 0
77// CHECK64: [[CALLEE:%.*]] = load void (%struct.C*, ...)** [[VPTR]]
78// CHECK64: musttail call void (%struct.C*, ...)* [[CALLEE]](%struct.C* %{{.*}}, ...)
79// CHECK64-NEXT: ret void
Hans Wennborg88497d62013-11-15 17:24:45 +000080// CHECK64: }
81
82// Thunk for calling the 2nd virtual function in C, taking int and double as parameters, returning int.
David Majnemer8c9cdb62015-01-21 01:21:31 +000083// CHECK32-LABEL: define linkonce_odr x86_thiscallcc void @"\01??_9C@@$B3AE"(%struct.C* %this, ...) {{.*}} comdat
Reid Klecknerc3473512014-08-29 21:43:29 +000084// CHECK32: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)** %{{.*}}, i64 1
85// CHECK32: [[CALLEE:%.*]] = load void (%struct.C*, ...)** [[VPTR]]
86// CHECK32: musttail call x86_thiscallcc void (%struct.C*, ...)* [[CALLEE]](%struct.C* %{{.*}}, ...)
87// CHECK32-NEXT: ret void
Hans Wennborg88497d62013-11-15 17:24:45 +000088// CHECK32: }
89//
David Majnemer8c9cdb62015-01-21 01:21:31 +000090// CHECK64-LABEL: define linkonce_odr void @"\01??_9C@@$B7AA"(%struct.C* %this, ...) {{.*}} comdat
Reid Klecknerc3473512014-08-29 21:43:29 +000091// CHECK64: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)** %{{.*}}, i64 1
92// CHECK64: [[CALLEE:%.*]] = load void (%struct.C*, ...)** [[VPTR]]
93// CHECK64: musttail call void (%struct.C*, ...)* [[CALLEE]](%struct.C* %{{.*}}, ...)
94// CHECK64-NEXT: ret void
Hans Wennborg88497d62013-11-15 17:24:45 +000095// CHECK64: }
96
97// Thunk for calling the 3rd virtual function in C, taking an int parameter, returning a struct.
David Majnemer8c9cdb62015-01-21 01:21:31 +000098// CHECK32-LABEL: define linkonce_odr x86_thiscallcc void @"\01??_9C@@$B7AE"(%struct.C* %this, ...) {{.*}} comdat
Reid Klecknerc3473512014-08-29 21:43:29 +000099// CHECK32: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)** %{{.*}}, i64 2
100// CHECK32: [[CALLEE:%.*]] = load void (%struct.C*, ...)** [[VPTR]]
101// CHECK32: musttail call x86_thiscallcc void (%struct.C*, ...)* [[CALLEE]](%struct.C* %{{.*}}, ...)
102// CHECK32-NEXT: ret void
Hans Wennborg88497d62013-11-15 17:24:45 +0000103// CHECK32: }
104//
David Majnemer8c9cdb62015-01-21 01:21:31 +0000105// CHECK64-LABEL: define linkonce_odr void @"\01??_9C@@$BBA@AA"(%struct.C* %this, ...) {{.*}} comdat
Reid Klecknerc3473512014-08-29 21:43:29 +0000106// CHECK64: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)** %{{.*}}, i64 2
107// CHECK64: [[CALLEE:%.*]] = load void (%struct.C*, ...)** [[VPTR]]
108// CHECK64: musttail call void (%struct.C*, ...)* [[CALLEE]](%struct.C* %{{.*}}, ...)
109// CHECK64-NEXT: ret void
Hans Wennborg88497d62013-11-15 17:24:45 +0000110// CHECK64: }
111
112// Thunk for calling the virtual function in internal class D.
Reid Klecknerc3473512014-08-29 21:43:29 +0000113// CHECK32-LABEL: define internal x86_thiscallcc void @"\01??_9D@?A@@$BA@AE"(%"struct.(anonymous namespace)::D"* %this, ...)
114// CHECK32: [[VPTR:%.*]] = getelementptr inbounds void (%"struct.(anonymous namespace)::D"*, ...)** %{{.*}}, i64 0
115// CHECK32: [[CALLEE:%.*]] = load void (%"struct.(anonymous namespace)::D"*, ...)** [[VPTR]]
116// CHECK32: musttail call x86_thiscallcc void (%"struct.(anonymous namespace)::D"*, ...)* [[CALLEE]](%"struct.(anonymous namespace)::D"* %{{.*}}, ...)
117// CHECK32-NEXT: ret void
Hans Wennborg88497d62013-11-15 17:24:45 +0000118// CHECK32: }
119//
Reid Klecknerc3473512014-08-29 21:43:29 +0000120// CHECK64-LABEL: define internal void @"\01??_9D@?A@@$BA@AA"(%"struct.(anonymous namespace)::D"* %this, ...)
121// CHECK64: [[VPTR:%.*]] = getelementptr inbounds void (%"struct.(anonymous namespace)::D"*, ...)** %{{.*}}, i64 0
122// CHECK64: [[CALLEE:%.*]] = load void (%"struct.(anonymous namespace)::D"*, ...)** [[VPTR]]
123// CHECK64: musttail call void (%"struct.(anonymous namespace)::D"*, ...)* [[CALLEE]](%"struct.(anonymous namespace)::D"* %{{.*}}, ...)
124// CHECK64-NEXT: ret void
Reid Kleckner966abe72014-05-15 23:01:46 +0000125// CHECK64: }
126
Reid Klecknerab2090d2014-07-26 01:34:32 +0000127// Thunk for calling the fourth virtual function in C, taking a struct parameter
128// and returning a struct.
David Majnemer8c9cdb62015-01-21 01:21:31 +0000129// CHECK32-LABEL: define linkonce_odr x86_thiscallcc void @"\01??_9C@@$BM@AE"(%struct.C* %this, ...) {{.*}} comdat
Reid Klecknerc3473512014-08-29 21:43:29 +0000130// CHECK32: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)** %{{.*}}, i64 3
131// CHECK32: [[CALLEE:%.*]] = load void (%struct.C*, ...)** [[VPTR]]
132// CHECK32: musttail call x86_thiscallcc void (%struct.C*, ...)* [[CALLEE]](%struct.C* %{{.*}}, ...)
133// CHECK32-NEXT: ret void
Reid Kleckner966abe72014-05-15 23:01:46 +0000134// CHECK32: }
135//
David Majnemer8c9cdb62015-01-21 01:21:31 +0000136// CHECK64-LABEL: define linkonce_odr void @"\01??_9C@@$BBI@AA"(%struct.C* %this, ...) {{.*}} comdat
Reid Klecknerc3473512014-08-29 21:43:29 +0000137// CHECK64: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)** %{{.*}}, i64 3
138// CHECK64: [[CALLEE:%.*]] = load void (%struct.C*, ...)** [[VPTR]]
139// CHECK64: musttail call void (%struct.C*, ...)* [[CALLEE]](%struct.C* %{{.*}}, ...)
Reid Klecknerab2090d2014-07-26 01:34:32 +0000140// CHECK64: ret void
141// CHECK64: }