Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGenCXX / ms-thunks-unprototyped.cpp
blob46fd33c58f6aeff597194c79e6d295e12ddf30ba
1 // RUN: %clang_cc1 -fno-rtti-data -triple x86_64-windows-msvc -emit-llvm %s -o - | FileCheck %s
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.
6 struct Incomplete;
7 template <typename T>
8 struct DoNotInstantiate {
9 typename T::does_not_exist field;
11 template <typename T>
12 struct InstantiateLater;
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;
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;
24 struct C : B { int c; };
25 C c;
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;
33 // CHECK: @"??_7S@@6BB2@@@" = linkonce_odr unnamed_addr constant
34 // CHECK-SAME: ptr @"?f@S@@W7EAA?AU?$DoNotInstantiate@X@@XZ"
36 // CHECK: @"??_7C@@6B@" = linkonce_odr unnamed_addr constant
37 // CHECK-SAME: ptr @"?foo@B@@W7EAAXUIncomplete@@@Z"
38 // CHECK-SAME: ptr @"?bar@B@@W7EAAXU?$DoNotInstantiate@H@@@Z"
39 // CHECK-SAME: ptr @"?baz@B@@W7EAAHU?$InstantiateLater@H@@@Z"
42 // CHECK-LABEL: define linkonce_odr dso_local void @"?f@S@@W7EAA?AU?$DoNotInstantiate@X@@XZ"(ptr noundef %this, ...)
43 // CHECK: %[[THIS_ADJ_i8:[^ ]*]] = getelementptr i8, ptr {{.*}}, i32 -8
44 // CHECK: musttail call void (ptr, ...) {{.*}}@"?f@S@@UEAA?AU?$DoNotInstantiate@X@@XZ"
45 // CHECK-SAME: (ptr noundef %[[THIS_ADJ_i8]], ...)
46 // CHECK: ret void
48 // The thunks should have a -8 adjustment.
50 // CHECK-LABEL: define linkonce_odr dso_local void @"?foo@B@@W7EAAXUIncomplete@@@Z"(ptr noundef %this, ...)
51 // CHECK: %[[THIS_ADJ_i8:[^ ]*]] = getelementptr i8, ptr {{.*}}, i32 -8
52 // CHECK: musttail call void (ptr, ...) {{.*}}@"?foo@B@@UEAAXUIncomplete@@@Z"
53 // CHECK-SAME: (ptr noundef %[[THIS_ADJ_i8]], ...)
54 // CHECK-NEXT: ret void
56 // CHECK-LABEL: define linkonce_odr dso_local void @"?bar@B@@W7EAAXU?$DoNotInstantiate@H@@@Z"(ptr noundef %this, ...)
57 // CHECK: %[[THIS_ADJ_i8:[^ ]*]] = getelementptr i8, ptr {{.*}}, i32 -8
58 // CHECK: musttail call void (ptr, ...) {{.*}}@"?bar@B@@UEAAXU?$DoNotInstantiate@H@@@Z"
59 // CHECK-SAME: (ptr noundef %[[THIS_ADJ_i8]], ...)
60 // CHECK-NEXT: ret void
62 // If we complete the definition later, things work out.
63 template <typename T> struct InstantiateLater { T x; };
64 inline int B::baz(InstantiateLater<int> p) { return p.x; }
66 // CHECK-LABEL: define linkonce_odr dso_local noundef i32 @"?baz@B@@W7EAAHU?$InstantiateLater@H@@@Z"(ptr noundef %this, i32 %p.coerce)
67 // CHECK: = getelementptr i8, ptr {{.*}}, i32 -8
68 // CHECK: tail call noundef i32 @"?baz@B@@UEAAHU?$InstantiateLater@H@@@Z"(ptr {{[^,]*}}, i32 {{.*}})
70 // CHECK-LABEL: define linkonce_odr dso_local noundef i32 @"?baz@B@@UEAAHU?$InstantiateLater@H@@@Z"(ptr noundef %this, i32 %p.coerce)