1 // RUN: %clang_cc1 -fno-rtti -emit-llvm %s -o - -mconstructor-aliases -triple=i386-pc-win32 | FileCheck %s
11 struct ChildNoOverride
: Left
, Right
{
14 struct ChildOverride
: Left
, Right
{
19 extern "C" void foo(void *);
21 void call_left_no_override(ChildNoOverride
*child
) {
22 // CHECK-LABEL: define dso_local void @"?call_left_no_override
23 // CHECK: %[[CHILD:.*]] = load ptr
26 // Only need to cast 'this' to Left*.
27 // CHECK: %[[VFTABLE:.*]] = load ptr, ptr %[[CHILD]]
28 // CHECK: %[[VFUN:.*]] = getelementptr inbounds ptr, ptr %[[VFTABLE]], i64 0
29 // CHECK: %[[VFUN_VALUE:.*]] = load ptr, ptr %[[VFUN]]
30 // CHECK: call x86_thiscallcc void %[[VFUN_VALUE]](ptr {{[^,]*}} %[[CHILD]])
34 void ChildOverride::left() {
35 // CHECK-LABEL: define dso_local x86_thiscallcc void @"?left@ChildOverride@@UAEXXZ"
36 // CHECK-SAME: (ptr {{[^,]*}} %[[THIS:.*]])
38 // No need to adjust 'this' as the ChildOverride's layout begins with Left.
39 // CHECK: %[[THIS_ADDR:.*]] = alloca ptr, align 4
40 // CHECK: store ptr %[[THIS]], ptr %[[THIS_ADDR]], align 4
43 // CHECK: %[[THIS:.*]] = load ptr, ptr %[[THIS_ADDR]]
44 // CHECK: call void @foo(ptr noundef %[[THIS]])
48 void call_left_override(ChildOverride
*child
) {
49 // CHECK-LABEL: define dso_local void @"?call_left_override
50 // CHECK: %[[CHILD:.*]] = load ptr
53 // CHECK: %[[VFTABLE:.*]] = load ptr, ptr %[[CHILD]]
54 // CHECK: %[[VFUN:.*]] = getelementptr inbounds ptr, ptr %[[VFTABLE]], i64 0
55 // CHECK: %[[VFUN_VALUE:.*]] = load ptr, ptr %[[VFUN]]
57 // CHECK: call x86_thiscallcc void %[[VFUN_VALUE]](ptr {{[^,]*}} %[[CHILD]])
61 void call_right_no_override(ChildNoOverride
*child
) {
62 // CHECK-LABEL: define dso_local void @"?call_right_no_override
63 // CHECK: %[[CHILD:.*]] = load ptr
66 // When calling a right base's virtual method, one needs to adjust 'this' at
69 // CHECK: %[[RIGHT_i8:.*]] = getelementptr inbounds i8, ptr %[[CHILD]], i32 4
71 // CHECK: %[[VFTABLE:.*]] = load ptr, ptr %[[RIGHT_i8]]
72 // CHECK: %[[VFUN:.*]] = getelementptr inbounds ptr, ptr %[[VFTABLE]], i64 0
73 // CHECK: %[[VFUN_VALUE:.*]] = load ptr, ptr %[[VFUN]]
74 // CHECK: call x86_thiscallcc void %[[VFUN_VALUE]](ptr {{[^,]*}} %[[RIGHT_i8]])
78 void ChildOverride::right() {
79 // CHECK-LABEL: define dso_local x86_thiscallcc void @"?right@ChildOverride@@UAEXXZ"(ptr
81 // ChildOverride::right gets 'this' cast to Right* in ECX (i.e. this+4) so we
82 // need to adjust 'this' before use.
84 // CHECK: %[[THIS_ADDR:.*]] = alloca ptr, align 4
85 // CHECK: store ptr %[[ECX:.*]], ptr %[[THIS_ADDR]], align 4
86 // CHECK: %[[THIS_RELOAD:.*]] = load ptr, ptr %[[THIS_ADDR]]
87 // CHECK: %[[THIS_ADJUSTED:.*]] = getelementptr inbounds i8, ptr %[[THIS_RELOAD]], i32 -4
90 // CHECK: call void @foo(ptr noundef %[[THIS_ADJUSTED]])
94 void call_right_override(ChildOverride
*child
) {
95 // CHECK-LABEL: define dso_local void @"?call_right_override
96 // CHECK: %[[CHILD:.*]] = load ptr
99 // When calling a right child's virtual method, one needs to adjust 'this' at
102 // CHECK: %[[RIGHT:.*]] = getelementptr inbounds i8, ptr %[[CHILD]], i32 4
104 // CHECK: %[[VFPTR_i8:.*]] = getelementptr inbounds i8, ptr %[[CHILD]], i32 4
105 // CHECK: %[[VFTABLE:.*]] = load ptr, ptr %[[VFPTR_i8]]
106 // CHECK: %[[VFUN:.*]] = getelementptr inbounds ptr, ptr %[[VFTABLE]], i64 0
107 // CHECK: %[[VFUN_VALUE:.*]] = load ptr, ptr %[[VFUN]]
109 // CHECK: call x86_thiscallcc void %[[VFUN_VALUE]](ptr noundef %[[RIGHT]])
113 struct GrandchildOverride
: ChildOverride
{
114 virtual void right();
117 void GrandchildOverride::right() {
118 // CHECK-LABEL: define dso_local x86_thiscallcc void @"?right@GrandchildOverride@@UAEXXZ"(ptr
120 // CHECK: %[[THIS_ADDR:.*]] = alloca ptr, align 4
121 // CHECK: store ptr %[[ECX:.*]], ptr %[[THIS_ADDR]], align 4
122 // CHECK: %[[THIS_RELOAD:.*]] = load ptr, ptr %[[THIS_ADDR]]
123 // CHECK: %[[THIS_ADJUSTED:.*]] = getelementptr inbounds i8, ptr %[[THIS_RELOAD]], i32 -4
126 // CHECK: call void @foo(ptr noundef %[[THIS_ADJUSTED]])
130 void call_grandchild_right(GrandchildOverride
*obj
) {
131 // Just make sure we don't crash.
137 // CHECK-LABEL: define {{.*}} @"??0Left@@QAE@XZ"
138 // CHECK-NOT: getelementptr
139 // CHECK: store ptr @"??_7Left@@6B@"
143 // CHECK-LABEL: define {{.*}} @"??0Right@@QAE@XZ"
144 // CHECK-NOT: getelementptr
145 // CHECK: store ptr @"??_7Right@@6B@"
149 // CHECK-LABEL: define {{.*}} @"??0ChildOverride@@QAE@XZ"
150 // CHECK: %[[THIS:.*]] = load ptr, ptr
151 // CHECK: store ptr @"??_7ChildOverride@@6BLeft@@@", ptr %[[THIS]]
152 // CHECK: %[[VFPTR_i8:.*]] = getelementptr inbounds i8, ptr %[[THIS]], i32 4
153 // CHECK: store ptr @"??_7ChildOverride@@6BRight@@@", ptr %[[VFPTR_i8]]
156 GrandchildOverride gc
;
157 // CHECK-LABEL: define {{.*}} @"??0GrandchildOverride@@QAE@XZ"
158 // CHECK: %[[THIS:.*]] = load ptr, ptr
159 // CHECK: store ptr @"??_7GrandchildOverride@@6BLeft@@@", ptr %[[THIS]]
160 // CHECK: %[[VFPTR_i8:.*]] = getelementptr inbounds i8, ptr %[[THIS]], i32 4
161 // CHECK: store ptr @"??_7GrandchildOverride@@6BRight@@@", ptr %[[VFPTR_i8]]
165 struct LeftWithNonVirtualDtor
{
167 ~LeftWithNonVirtualDtor();
170 struct AsymmetricChild
: LeftWithNonVirtualDtor
, Right
{
171 virtual ~AsymmetricChild();
174 void call_asymmetric_child_complete_dtor() {
175 // CHECK-LABEL: define dso_local void @"?call_asymmetric_child_complete_dtor@@YAXXZ"
177 // CHECK: call x86_thiscallcc noundef ptr @"??0AsymmetricChild@@QAE@XZ"(ptr {{[^,]*}} %[[OBJ:.*]])
178 // CHECK-NOT: getelementptr
179 // CHECK: call x86_thiscallcc void @"??1AsymmetricChild@@UAE@XZ"(ptr {{[^,]*}} %[[OBJ]])