[InstCombine] Preserve NSW flags for `lshr (mul nuw X, C1), C2 -> mul nuw nsw X,...
[llvm-project.git] / clang / test / CodeGenCXX / microsoft-abi-multiple-nonvirtual-inheritance.cpp
blobf9d6473cb6c6220474311d51da704cff26bbb45c
1 // RUN: %clang_cc1 -fno-rtti -emit-llvm %s -o - -mconstructor-aliases -triple=i386-pc-win32 | FileCheck %s
3 struct Left {
4 virtual void left();
5 };
7 struct Right {
8 virtual void right();
9 };
11 struct ChildNoOverride : Left, Right {
14 struct ChildOverride : Left, Right {
15 virtual void left();
16 virtual void 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
25 child->left();
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]])
31 // CHECK: ret
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
42 foo(this);
43 // CHECK: %[[THIS:.*]] = load ptr, ptr %[[THIS_ADDR]]
44 // CHECK: call void @foo(ptr noundef %[[THIS]])
45 // CHECK: ret
48 void call_left_override(ChildOverride *child) {
49 // CHECK-LABEL: define dso_local void @"?call_left_override
50 // CHECK: %[[CHILD:.*]] = load ptr
52 child->left();
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]])
58 // CHECK: ret
61 void call_right_no_override(ChildNoOverride *child) {
62 // CHECK-LABEL: define dso_local void @"?call_right_no_override
63 // CHECK: %[[CHILD:.*]] = load ptr
65 child->right();
66 // When calling a right base's virtual method, one needs to adjust 'this' at
67 // the caller site.
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]])
75 // CHECK: ret
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
89 foo(this);
90 // CHECK: call void @foo(ptr noundef %[[THIS_ADJUSTED]])
91 // CHECK: ret
94 void call_right_override(ChildOverride *child) {
95 // CHECK-LABEL: define dso_local void @"?call_right_override
96 // CHECK: %[[CHILD:.*]] = load ptr
98 child->right();
99 // When calling a right child's virtual method, one needs to adjust 'this' at
100 // the caller site.
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]])
110 // CHECK: ret
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
125 foo(this);
126 // CHECK: call void @foo(ptr noundef %[[THIS_ADJUSTED]])
127 // CHECK: ret
130 void call_grandchild_right(GrandchildOverride *obj) {
131 // Just make sure we don't crash.
132 obj->right();
135 void emit_ctors() {
136 Left l;
137 // CHECK-LABEL: define {{.*}} @"??0Left@@QAE@XZ"
138 // CHECK-NOT: getelementptr
139 // CHECK: store ptr @"??_7Left@@6B@"
140 // CHECK: ret
142 Right r;
143 // CHECK-LABEL: define {{.*}} @"??0Right@@QAE@XZ"
144 // CHECK-NOT: getelementptr
145 // CHECK: store ptr @"??_7Right@@6B@"
146 // CHECK: ret
148 ChildOverride co;
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]]
154 // CHECK: ret
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]]
162 // CHECK: ret
165 struct LeftWithNonVirtualDtor {
166 virtual void left();
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"
176 AsymmetricChild obj;
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]])
180 // CHECK: ret