Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1 | // 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 Wennborg | 93b717a | 2013-11-15 17:24:45 +0000 | [diff] [blame] | 3 | |
| 4 | struct S { |
| 5 | int x, y, z; |
| 6 | }; |
| 7 | |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 8 | // U is not trivially copyable, and requires inalloca to pass by value. |
| 9 | struct U { |
| 10 | int u; |
| 11 | U(); |
| 12 | ~U(); |
| 13 | U(const U &); |
| 14 | }; |
| 15 | |
Hans Wennborg | 93b717a | 2013-11-15 17:24:45 +0000 | [diff] [blame] | 16 | struct C { |
| 17 | virtual void foo(); |
| 18 | virtual int bar(int, double); |
| 19 | virtual S baz(int); |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 20 | virtual S qux(U); |
Hans Wennborg | 93b717a | 2013-11-15 17:24:45 +0000 | [diff] [blame] | 21 | }; |
| 22 | |
| 23 | namespace { |
| 24 | struct D { |
| 25 | virtual void foo(); |
| 26 | }; |
| 27 | } |
| 28 | |
| 29 | void 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 Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 43 | S (C::*ptr5)(U); |
| 44 | ptr5 = &C::qux; |
| 45 | |
| 46 | |
Hans Wennborg | 93b717a | 2013-11-15 17:24:45 +0000 | [diff] [blame] | 47 | // CHECK32-LABEL: define void @"\01?f@@YAXXZ"() |
| 48 | // CHECK32: store i8* bitcast (void (%struct.C*)* @"\01??_9C@@$BA@AE" to i8*), i8** %ptr |
| 49 | // CHECK32: store i8* bitcast (i32 (%struct.C*, i32, double)* @"\01??_9C@@$B3AE" to i8*), i8** %ptr2 |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 50 | // CHECK32: store i8* bitcast (void (%struct.C*, %struct.S*, i32)* @"\01??_9C@@$B7AE" to i8*), i8** %ptr3 |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 51 | // CHECK32: store i8* bitcast (void (%"struct.(anonymous namespace)::D"*)* @"\01??_9D@?A@@$BA@AE" to i8*), i8** %ptr4 |
Hans Wennborg | 93b717a | 2013-11-15 17:24:45 +0000 | [diff] [blame] | 52 | // CHECK32: } |
| 53 | // |
| 54 | // CHECK64-LABEL: define void @"\01?f@@YAXXZ"() |
| 55 | // CHECK64: store i8* bitcast (void (%struct.C*)* @"\01??_9C@@$BA@AA" to i8*), i8** %ptr |
| 56 | // CHECK64: store i8* bitcast (i32 (%struct.C*, i32, double)* @"\01??_9C@@$B7AA" to i8*), i8** %ptr2 |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 57 | // CHECK64: store i8* bitcast (void (%struct.C*, %struct.S*, i32)* @"\01??_9C@@$BBA@AA" to i8*), i8** %ptr3 |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 58 | // CHECK64: store i8* bitcast (void (%"struct.(anonymous namespace)::D"*)* @"\01??_9D@?A@@$BA@AA" to i8*), i8** %ptr |
Hans Wennborg | 93b717a | 2013-11-15 17:24:45 +0000 | [diff] [blame] | 59 | // CHECK64: } |
| 60 | } |
| 61 | |
| 62 | |
| 63 | // Thunk for calling the 1st virtual function in C with no parameters. |
| 64 | // CHECK32-LABEL: define linkonce_odr x86_thiscallcc void @"\01??_9C@@$BA@AE"(%struct.C* %this) unnamed_addr |
| 65 | // CHECK32: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*)** %{{.*}}, i64 0 |
| 66 | // CHECK32: [[CALLEE:%.*]] = load void (%struct.C*)** [[VPTR]] |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 67 | // CHECK32: musttail call x86_thiscallcc void [[CALLEE]](%struct.C* %{{.*}}) |
Hans Wennborg | 93b717a | 2013-11-15 17:24:45 +0000 | [diff] [blame] | 68 | // CHECK32: ret void |
| 69 | // CHECK32: } |
| 70 | // |
| 71 | // CHECK64-LABEL: define linkonce_odr void @"\01??_9C@@$BA@AA"(%struct.C* %this) unnamed_addr |
| 72 | // CHECK64: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*)** %{{.*}}, i64 0 |
| 73 | // CHECK64: [[CALLEE:%.*]] = load void (%struct.C*)** [[VPTR]] |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 74 | // CHECK64: musttail call void [[CALLEE]](%struct.C* %{{.*}}) |
Hans Wennborg | 93b717a | 2013-11-15 17:24:45 +0000 | [diff] [blame] | 75 | // CHECK64: ret void |
| 76 | // CHECK64: } |
| 77 | |
| 78 | // Thunk for calling the 2nd virtual function in C, taking int and double as parameters, returning int. |
| 79 | // CHECK32-LABEL: define linkonce_odr x86_thiscallcc i32 @"\01??_9C@@$B3AE"(%struct.C* %this, i32, double) unnamed_addr |
| 80 | // CHECK32: [[VPTR:%.*]] = getelementptr inbounds i32 (%struct.C*, i32, double)** %{{.*}}, i64 1 |
| 81 | // CHECK32: [[CALLEE:%.*]] = load i32 (%struct.C*, i32, double)** [[VPTR]] |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 82 | // CHECK32: [[CALL:%.*]] = musttail call x86_thiscallcc i32 [[CALLEE]](%struct.C* %{{.*}}, i32 %{{.*}}, double %{{.*}}) |
Hans Wennborg | 93b717a | 2013-11-15 17:24:45 +0000 | [diff] [blame] | 83 | // CHECK32: ret i32 [[CALL]] |
| 84 | // CHECK32: } |
| 85 | // |
| 86 | // CHECK64-LABEL: define linkonce_odr i32 @"\01??_9C@@$B7AA"(%struct.C* %this, i32, double) unnamed_addr |
| 87 | // CHECK64: [[VPTR:%.*]] = getelementptr inbounds i32 (%struct.C*, i32, double)** %{{.*}}, i64 1 |
| 88 | // CHECK64: [[CALLEE:%.*]] = load i32 (%struct.C*, i32, double)** [[VPTR]] |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 89 | // CHECK64: [[CALL:%.*]] = musttail call i32 [[CALLEE]](%struct.C* %{{.*}}, i32 %{{.*}}, double %{{.*}}) |
Hans Wennborg | 93b717a | 2013-11-15 17:24:45 +0000 | [diff] [blame] | 90 | // CHECK64: ret i32 [[CALL]] |
| 91 | // CHECK64: } |
| 92 | |
| 93 | // Thunk for calling the 3rd virtual function in C, taking an int parameter, returning a struct. |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 94 | // CHECK32-LABEL: define linkonce_odr x86_thiscallcc void @"\01??_9C@@$B7AE"(%struct.C* %this, %struct.S* noalias sret %agg.result, i32) unnamed_addr |
| 95 | // CHECK32: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, %struct.S*, i32)** %{{.*}}, i64 2 |
| 96 | // CHECK32: [[CALLEE:%.*]] = load void (%struct.C*, %struct.S*, i32)** [[VPTR]] |
| 97 | // CHECK32: musttail call x86_thiscallcc void [[CALLEE]](%struct.C* %{{.*}}, %struct.S* sret %agg.result, i32 %{{.*}}) |
Hans Wennborg | 93b717a | 2013-11-15 17:24:45 +0000 | [diff] [blame] | 98 | // CHECK32: ret void |
| 99 | // CHECK32: } |
| 100 | // |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 101 | // CHECK64-LABEL: define linkonce_odr void @"\01??_9C@@$BBA@AA"(%struct.C* %this, %struct.S* noalias sret %agg.result, i32) unnamed_addr |
| 102 | // CHECK64: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, %struct.S*, i32)** %{{.*}}, i64 2 |
| 103 | // CHECK64: [[CALLEE:%.*]] = load void (%struct.C*, %struct.S*, i32)** [[VPTR]] |
| 104 | // CHECK64: musttail call void [[CALLEE]](%struct.C* %{{.*}}, %struct.S* sret %agg.result, i32 %{{.*}}) |
Hans Wennborg | 93b717a | 2013-11-15 17:24:45 +0000 | [diff] [blame] | 105 | // CHECK64: ret void |
| 106 | // CHECK64: } |
| 107 | |
| 108 | // Thunk for calling the virtual function in internal class D. |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 109 | // CHECK32-LABEL: define internal x86_thiscallcc void @"\01??_9D@?A@@$BA@AE"(%"struct.(anonymous namespace)::D"* %this) unnamed_addr |
| 110 | // CHECK32: [[VPTR:%.*]] = getelementptr inbounds void (%"struct.(anonymous namespace)::D"*)** %{{.*}}, i64 0 |
| 111 | // CHECK32: [[CALLEE:%.*]] = load void (%"struct.(anonymous namespace)::D"*)** [[VPTR]] |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 112 | // CHECK32: musttail call x86_thiscallcc void [[CALLEE]](%"struct.(anonymous namespace)::D"* %{{.*}}) |
Hans Wennborg | 93b717a | 2013-11-15 17:24:45 +0000 | [diff] [blame] | 113 | // CHECK32: ret void |
| 114 | // CHECK32: } |
| 115 | // |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 116 | // CHECK64-LABEL: define internal void @"\01??_9D@?A@@$BA@AA"(%"struct.(anonymous namespace)::D"* %this) unnamed_addr |
| 117 | // CHECK64: [[VPTR:%.*]] = getelementptr inbounds void (%"struct.(anonymous namespace)::D"*)** %{{.*}}, i64 0 |
| 118 | // CHECK64: [[CALLEE:%.*]] = load void (%"struct.(anonymous namespace)::D"*)** [[VPTR]] |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 119 | // CHECK64: musttail call void [[CALLEE]](%"struct.(anonymous namespace)::D"* %{{.*}}) |
| 120 | // CHECK64: ret void |
| 121 | // CHECK64: } |
| 122 | |
| 123 | // Thunk for calling the fourth virtual function in C, taking a struct parameter and returning a struct. |
| 124 | // CHECK32-LABEL: define linkonce_odr x86_thiscallcc %struct.S* @"\01??_9C@@$BM@AE"(%struct.C* %this, <{ %struct.S*, %struct.U }>* inalloca) unnamed_addr |
| 125 | // CHECK32: [[VPTR:%.*]] = getelementptr inbounds %struct.S* (%struct.C*, <{ %struct.S*, %struct.U }>*)** %{{.*}}, i64 3 |
| 126 | // CHECK32: [[CALLEE:%.*]] = load %struct.S* (%struct.C*, <{ %struct.S*, %struct.U }>*)** [[VPTR]] |
| 127 | // CHECK32: [[CALL:%.*]] = musttail call x86_thiscallcc %struct.S* [[CALLEE]](%struct.C* %this, <{ %struct.S*, %struct.U }>* inalloca %{{.*}}) |
| 128 | // CHECK32: ret %struct.S* [[CALL]] |
| 129 | // CHECK32: } |
| 130 | // |
| 131 | // CHECK64-LABEL: define linkonce_odr void @"\01??_9C@@$BBI@AA"(%struct.C* %this, %struct.S* noalias sret %agg.result, %struct.U*) unnamed_addr |
| 132 | // CHECK64: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, %struct.S*, %struct.U*)** %{{.*}}, i64 3 |
| 133 | // CHECK64: [[CALLEE:%.*]] = load void (%struct.C*, %struct.S*, %struct.U*)** [[VPTR]] |
| 134 | // CHECK64: musttail call void [[CALLEE]](%struct.C* %this, %struct.S* sret %agg.result, %struct.U* %{{.*}}) |
Hans Wennborg | 93b717a | 2013-11-15 17:24:45 +0000 | [diff] [blame] | 135 | // CHECK64: ret void |
| 136 | // CHECK64: } |