blob: 51a04c89dcb7bec9c6e2302d410b73cd27cec82d [file] [log] [blame]
Hans Wennborg93b717a2013-11-15 17:24:45 +00001// RUN: %clang_cc1 -fno-rtti -emit-llvm -cxx-abi microsoft -triple=i386-pc-win32 %s -o - | FileCheck %s --check-prefix=CHECK32
2// RUN: %clang_cc1 -fno-rtti -emit-llvm -cxx-abi microsoft -triple=x86_64-pc-win32 %s -o - | FileCheck %s --check-prefix=CHECK64
3
4struct S {
5 int x, y, z;
6};
7
8struct C {
9 virtual void foo();
10 virtual int bar(int, double);
11 virtual S baz(int);
12};
13
14namespace {
15struct D {
16 virtual void foo();
17};
18}
19
20void f() {
21 void (C::*ptr)();
22 ptr = &C::foo;
23 ptr = &C::foo; // Don't crash trying to define the thunk twice :)
24
25 int (C::*ptr2)(int, double);
26 ptr2 = &C::bar;
27
28 S (C::*ptr3)(int);
29 ptr3 = &C::baz;
30
31 void (D::*ptr4)();
32 ptr4 = &D::foo;
33
34// CHECK32-LABEL: define void @"\01?f@@YAXXZ"()
35// CHECK32: store i8* bitcast (void (%struct.C*)* @"\01??_9C@@$BA@AE" to i8*), i8** %ptr
36// CHECK32: store i8* bitcast (i32 (%struct.C*, i32, double)* @"\01??_9C@@$B3AE" to i8*), i8** %ptr2
37// CHECK32: store i8* bitcast (void (%struct.S*, %struct.C*, i32)* @"\01??_9C@@$B7AE" to i8*), i8** %ptr3
38// CHECK32: store i8* bitcast (void (%"struct.<anonymous namespace>::D"*)* @"\01??_9D@?A@@$BA@AE" to i8*), i8** %ptr4
39// CHECK32: }
40//
41// CHECK64-LABEL: define void @"\01?f@@YAXXZ"()
42// CHECK64: store i8* bitcast (void (%struct.C*)* @"\01??_9C@@$BA@AA" to i8*), i8** %ptr
43// CHECK64: store i8* bitcast (i32 (%struct.C*, i32, double)* @"\01??_9C@@$B7AA" to i8*), i8** %ptr2
44// CHECK64: store i8* bitcast (void (%struct.S*, %struct.C*, i32)* @"\01??_9C@@$BBA@AA" to i8*), i8** %ptr3
45// CHECK64: store i8* bitcast (void (%"struct.<anonymous namespace>::D"*)* @"\01??_9D@?A@@$BA@AA" to i8*), i8** %ptr
46// CHECK64: }
47}
48
49
50// Thunk for calling the 1st virtual function in C with no parameters.
51// CHECK32-LABEL: define linkonce_odr x86_thiscallcc void @"\01??_9C@@$BA@AE"(%struct.C* %this) unnamed_addr
52// CHECK32: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*)** %{{.*}}, i64 0
53// CHECK32: [[CALLEE:%.*]] = load void (%struct.C*)** [[VPTR]]
54// CHECK32: call x86_thiscallcc void [[CALLEE]](%struct.C* %{{.*}})
55// CHECK32: ret void
56// CHECK32: }
57//
58// CHECK64-LABEL: define linkonce_odr void @"\01??_9C@@$BA@AA"(%struct.C* %this) unnamed_addr
59// CHECK64: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*)** %{{.*}}, i64 0
60// CHECK64: [[CALLEE:%.*]] = load void (%struct.C*)** [[VPTR]]
61// CHECK64: call void [[CALLEE]](%struct.C* %{{.*}})
62// CHECK64: ret void
63// CHECK64: }
64
65// Thunk for calling the 2nd virtual function in C, taking int and double as parameters, returning int.
66// CHECK32-LABEL: define linkonce_odr x86_thiscallcc i32 @"\01??_9C@@$B3AE"(%struct.C* %this, i32, double) unnamed_addr
67// CHECK32: [[VPTR:%.*]] = getelementptr inbounds i32 (%struct.C*, i32, double)** %{{.*}}, i64 1
68// CHECK32: [[CALLEE:%.*]] = load i32 (%struct.C*, i32, double)** [[VPTR]]
69// CHECK32: [[CALL:%.*]] = call x86_thiscallcc i32 [[CALLEE]](%struct.C* %{{.*}}, i32 %{{.*}}, double %{{.*}})
70// CHECK32: ret i32 [[CALL]]
71// CHECK32: }
72//
73// CHECK64-LABEL: define linkonce_odr i32 @"\01??_9C@@$B7AA"(%struct.C* %this, i32, double) unnamed_addr
74// CHECK64: [[VPTR:%.*]] = getelementptr inbounds i32 (%struct.C*, i32, double)** %{{.*}}, i64 1
75// CHECK64: [[CALLEE:%.*]] = load i32 (%struct.C*, i32, double)** [[VPTR]]
76// CHECK64: [[CALL:%.*]] = call i32 [[CALLEE]](%struct.C* %{{.*}}, i32 %{{.*}}, double %{{.*}})
77// CHECK64: ret i32 [[CALL]]
78// CHECK64: }
79
80// Thunk for calling the 3rd virtual function in C, taking an int parameter, returning a struct.
81// CHECK32-LABEL: define linkonce_odr x86_thiscallcc void @"\01??_9C@@$B7AE"(%struct.S* noalias sret %agg.result, %struct.C* %this, i32) unnamed_addr
82// CHECK32: [[VPTR:%.*]] = getelementptr inbounds void (%struct.S*, %struct.C*, i32)** %{{.*}}, i64 2
83// CHECK32: [[CALLEE:%.*]] = load void (%struct.S*, %struct.C*, i32)** [[VPTR]]
84// CHECK32: call x86_thiscallcc void [[CALLEE]](%struct.S* sret %agg.result, %struct.C* %{{.*}}, i32 %{{.*}})
85// CHECK32: ret void
86// CHECK32: }
87//
88// CHECK64-LABEL: define linkonce_odr void @"\01??_9C@@$BBA@AA"(%struct.S* noalias sret %agg.result, %struct.C* %this, i32) unnamed_addr
89// CHECK64: [[VPTR:%.*]] = getelementptr inbounds void (%struct.S*, %struct.C*, i32)** %{{.*}}, i64 2
90// CHECK64: [[CALLEE:%.*]] = load void (%struct.S*, %struct.C*, i32)** [[VPTR]]
91// CHECK64: call void [[CALLEE]](%struct.S* sret %agg.result, %struct.C* %{{.*}}, i32 %{{.*}})
92// CHECK64: ret void
93// CHECK64: }
94
95// Thunk for calling the virtual function in internal class D.
96// CHECK32-LABEL: define internal x86_thiscallcc void @"\01??_9D@?A@@$BA@AE"(%"struct.<anonymous namespace>::D"* %this) unnamed_addr
97// CHECK32: [[VPTR:%.*]] = getelementptr inbounds void (%"struct.<anonymous namespace>::D"*)** %{{.*}}, i64 0
98// CHECK32: [[CALLEE:%.*]] = load void (%"struct.<anonymous namespace>::D"*)** [[VPTR]]
99// CHECK32: call x86_thiscallcc void [[CALLEE]](%"struct.<anonymous namespace>::D"* %{{.*}})
100// CHECK32: ret void
101// CHECK32: }
102//
103// CHECK64-LABEL: define internal void @"\01??_9D@?A@@$BA@AA"(%"struct.<anonymous namespace>::D"* %this) unnamed_addr
104// CHECK64: [[VPTR:%.*]] = getelementptr inbounds void (%"struct.<anonymous namespace>::D"*)** %{{.*}}, i64 0
105// CHECK64: [[CALLEE:%.*]] = load void (%"struct.<anonymous namespace>::D"*)** [[VPTR]]
106// CHECK64: call void [[CALLEE]](%"struct.<anonymous namespace>::D"* %{{.*}})
107// CHECK64: ret void
108// CHECK64: }