| 1 | // RUN: %clang_cc1 -fno-rtti-data -triple x86_64-windows-msvc -emit-llvm %s -o - | FileCheck %s |
| 2 | |
| 3 | // In this example, C does not override B::foo, but it needs to emit a thunk to |
| 4 | // adjust for the relative difference of position between A-in-B and A-in-C. |
| 5 | |
| 6 | struct Incomplete; |
| 7 | template <typename T> |
| 8 | struct DoNotInstantiate { |
| 9 | typename T::does_not_exist field; |
| 10 | }; |
| 11 | template <typename T> |
| 12 | struct InstantiateLater; |
| 13 | |
| 14 | struct A { |
| 15 | virtual void foo(Incomplete p) = 0; |
| 16 | virtual void bar(DoNotInstantiate<int> p) = 0; |
| 17 | virtual int baz(InstantiateLater<int> p) = 0; |
| 18 | }; |
| 19 | struct B : virtual A { |
| 20 | void foo(Incomplete p) override; |
| 21 | void bar(DoNotInstantiate<int> p) override; |
| 22 | inline int baz(InstantiateLater<int> p) override; |
| 23 | }; |
| 24 | struct C : B { int c; }; |
| 25 | C c; |
| 26 | |
| 27 | // Do the same thing, but with an incomplete return type. |
| 28 | struct B1 { virtual DoNotInstantiate<void> f() = 0; }; |
| 29 | struct B2 { virtual DoNotInstantiate<void> f() = 0; }; |
| 30 | struct S : B1, B2 { DoNotInstantiate<void> f() override; }; |
| 31 | S s; |
| 32 | |
| 33 | // CHECK: @"??_7S@@6BB2@@@" = linkonce_odr unnamed_addr constant |
| 34 | // CHECK-SAME: void (%struct.S*, ...)* @"?f@S@@W7EAA?AU?$DoNotInstantiate@X@@XZ" |
| 35 | |
| 36 | // CHECK: @"??_7C@@6B@" = linkonce_odr unnamed_addr constant |
| 37 | // CHECK-SAME: void (%struct.B*, ...)* @"?foo@B@@W7EAAXUIncomplete@@@Z" |
| 38 | // CHECK-SAME: void (%struct.B*, ...)* @"?bar@B@@W7EAAXU?$DoNotInstantiate@H@@@Z" |
| 39 | // CHECK-SAME: i32 (i8*, i32)* @"?baz@B@@W7EAAHU?$InstantiateLater@H@@@Z" |
| 40 | |
| 41 | |
| 42 | // CHECK-LABEL: define linkonce_odr dso_local void @"?f@S@@W7EAA?AU?$DoNotInstantiate@X@@XZ"(%struct.S* %this, ...) |
| 43 | // CHECK: %[[THIS_ADJ_i8:[^ ]*]] = getelementptr i8, i8* {{.*}}, i32 -8 |
| 44 | // CHECK: %[[THIS_ADJ:[^ ]*]] = bitcast i8* %[[THIS_ADJ_i8]] to %struct.S* |
| 45 | // CHECK: musttail call void (%struct.S*, ...) {{.*}}@"?f@S@@UEAA?AU?$DoNotInstantiate@X@@XZ" |
| 46 | // CHECK-SAME: (%struct.S* %[[THIS_ADJ]], ...) |
| 47 | // CHECK: ret void |
| 48 | |
| 49 | // The thunks should have a -8 adjustment. |
| 50 | |
| 51 | // CHECK-LABEL: define linkonce_odr dso_local void @"?foo@B@@W7EAAXUIncomplete@@@Z"(%struct.B* %this, ...) |
| 52 | // CHECK: %[[THIS_ADJ_i8:[^ ]*]] = getelementptr i8, i8* {{.*}}, i32 -8 |
| 53 | // CHECK: %[[THIS_ADJ:[^ ]*]] = bitcast i8* %[[THIS_ADJ_i8]] to %struct.B* |
| 54 | // CHECK: musttail call void (%struct.B*, ...) {{.*}}@"?foo@B@@UEAAXUIncomplete@@@Z" |
| 55 | // CHECK-SAME: (%struct.B* %[[THIS_ADJ]], ...) |
| 56 | // CHECK-NEXT: ret void |
| 57 | |
| 58 | // CHECK-LABEL: define linkonce_odr dso_local void @"?bar@B@@W7EAAXU?$DoNotInstantiate@H@@@Z"(%struct.B* %this, ...) |
| 59 | // CHECK: %[[THIS_ADJ_i8:[^ ]*]] = getelementptr i8, i8* {{.*}}, i32 -8 |
| 60 | // CHECK: %[[THIS_ADJ:[^ ]*]] = bitcast i8* %[[THIS_ADJ_i8]] to %struct.B* |
| 61 | // CHECK: musttail call void (%struct.B*, ...) {{.*}}@"?bar@B@@UEAAXU?$DoNotInstantiate@H@@@Z" |
| 62 | // CHECK-SAME: (%struct.B* %[[THIS_ADJ]], ...) |
| 63 | // CHECK-NEXT: ret void |
| 64 | |
| 65 | // If we complete the definition later, things work out. |
| 66 | template <typename T> struct InstantiateLater { T x; }; |
| 67 | inline int B::baz(InstantiateLater<int> p) { return p.x; } |
| 68 | |
| 69 | // CHECK-LABEL: define linkonce_odr dso_local i32 @"?baz@B@@W7EAAHU?$InstantiateLater@H@@@Z"(i8* %this.coerce, i32 %p.coerce) |
| 70 | // CHECK: = getelementptr i8, i8* {{.*}}, i32 -8 |
| 71 | // CHECK: tail call i32 @"?baz@B@@UEAAHU?$InstantiateLater@H@@@Z"(i8* {{[^,]*}}, i32 {{.*}}) |
| 72 | |
| 73 | // CHECK-LABEL: define linkonce_odr dso_local i32 @"?baz@B@@UEAAHU?$InstantiateLater@H@@@Z"(i8* %this.coerce, i32 %p.coerce) |
| 74 | |