diff options
Diffstat (limited to 'clang/test')
| -rw-r--r-- | clang/test/CodeGenCXX/ms-thunks-unprototyped-return.cpp | 15 | ||||
| -rw-r--r-- | clang/test/CodeGenCXX/ms-thunks-unprototyped.cpp | 56 |
2 files changed, 71 insertions, 0 deletions
diff --git a/clang/test/CodeGenCXX/ms-thunks-unprototyped-return.cpp b/clang/test/CodeGenCXX/ms-thunks-unprototyped-return.cpp new file mode 100644 index 00000000000..ef39fd70607 --- /dev/null +++ b/clang/test/CodeGenCXX/ms-thunks-unprototyped-return.cpp @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -fno-rtti-data -triple x86_64-windows-msvc -emit-llvm-only %s -verify + +// Verify that we error out on this return adjusting thunk that we can't emit. + +struct Incomplete; + +struct A { + virtual A * clone(Incomplete p) = 0; +}; +struct B : virtual A { + // expected-error@+1 2 {{cannot compile this return-adjusting thunk with incomplete parameter type yet}} + B * clone(Incomplete p) override; +}; +struct C : B { int c; }; +C c; diff --git a/clang/test/CodeGenCXX/ms-thunks-unprototyped.cpp b/clang/test/CodeGenCXX/ms-thunks-unprototyped.cpp new file mode 100644 index 00000000000..b2ca5cb0d13 --- /dev/null +++ b/clang/test/CodeGenCXX/ms-thunks-unprototyped.cpp @@ -0,0 +1,56 @@ +// RUN: %clang_cc1 -fno-rtti-data -triple x86_64-windows-msvc -emit-llvm %s -o - | FileCheck %s + +// In this example, C does not override B::foo, but it needs to emit a thunk to +// adjust for the relative difference of position between A-in-B and A-in-C. + +struct Incomplete; +template <typename T> +struct DoNotInstantiate { + typename T::does_not_exist field; +}; +template <typename T> +struct InstantiateLater; + +struct A { + virtual void foo(Incomplete p) = 0; + virtual void bar(DoNotInstantiate<int> p) = 0; + virtual int baz(InstantiateLater<int> p) = 0; +}; +struct B : virtual A { + void foo(Incomplete p) override; + void bar(DoNotInstantiate<int> p) override; + inline int baz(InstantiateLater<int> p) override; +}; +struct C : B { int c; }; +C c; + +// CHECK: @"??_7C@@6B@" = linkonce_odr unnamed_addr constant +// CHECK-SAME: void (%struct.B*, ...)* @"?foo@B@@W7EAAXUIncomplete@@@Z" +// CHECK-SAME: void (%struct.B*, ...)* @"?bar@B@@W7EAAXU?$DoNotInstantiate@H@@@Z" +// CHECK-SAME: i32 (i8*, i32)* @"?baz@B@@W7EAAHU?$InstantiateLater@H@@@Z" + +// The thunks should have a -8 adjustment. + +// CHECK-LABEL: define linkonce_odr dso_local void @"?foo@B@@W7EAAXUIncomplete@@@Z"(%struct.B* %this, ...) +// CHECK: %[[THIS_ADJ_i8:[^ ]*]] = getelementptr i8, i8* {{.*}}, i32 -8 +// CHECK: %[[THIS_ADJ:[^ ]*]] = bitcast i8* %[[THIS_ADJ_i8]] to %struct.B* +// CHECK: musttail call void (%struct.B*, ...) {{.*}}@"?foo@B@@UEAAXUIncomplete@@@Z" +// CHECK-SAME: (%struct.B* %[[THIS_ADJ]], ...) +// CHECK-NEXT: ret void + +// CHECK-LABEL: define linkonce_odr dso_local void @"?bar@B@@W7EAAXU?$DoNotInstantiate@H@@@Z"(%struct.B* %this, ...) +// CHECK: %[[THIS_ADJ_i8:[^ ]*]] = getelementptr i8, i8* {{.*}}, i32 -8 +// CHECK: %[[THIS_ADJ:[^ ]*]] = bitcast i8* %[[THIS_ADJ_i8]] to %struct.B* +// CHECK: musttail call void (%struct.B*, ...) {{.*}}@"?bar@B@@UEAAXU?$DoNotInstantiate@H@@@Z" +// CHECK-SAME: (%struct.B* %[[THIS_ADJ]], ...) +// CHECK-NEXT: ret void + +// If we complete the definition later, things work out. +template <typename T> struct InstantiateLater { T x; }; +inline int B::baz(InstantiateLater<int> p) { return p.x; } + +// CHECK-LABEL: define linkonce_odr dso_local i32 @"?baz@B@@W7EAAHU?$InstantiateLater@H@@@Z"(i8* %this.coerce, i32 %p.coerce) +// CHECK: = getelementptr i8, i8* {{.*}}, i32 -8 +// CHECK: tail call i32 @"?baz@B@@UEAAHU?$InstantiateLater@H@@@Z"(i8* {{[^,]*}}, i32 {{.*}}) + +// CHECK-LABEL: define linkonce_odr dso_local i32 @"?baz@B@@UEAAHU?$InstantiateLater@H@@@Z"(i8* %this.coerce, i32 %p.coerce) |

