annotate clang/test/CodeGenCXX/microsoft-abi-structors.cpp @ 206:f17a3b42b08b

Added tag before-12 for changeset b7591485f4cd
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 07 Jun 2021 21:25:57 +0900
parents 1d019706d866
children 2e18cbf3894f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -emit-llvm -fno-rtti %s -std=c++11 -o - -mconstructor-aliases -triple=i386-pc-win32 -fno-rtti > %t
anatofuz
parents:
diff changeset
2 // RUN: FileCheck %s < %t
anatofuz
parents:
diff changeset
3 // vftables are emitted very late, so do another pass to try to keep the checks
anatofuz
parents:
diff changeset
4 // in source order.
anatofuz
parents:
diff changeset
5 // RUN: FileCheck --check-prefix DTORS %s < %t
anatofuz
parents:
diff changeset
6 // RUN: FileCheck --check-prefix DTORS2 %s < %t
anatofuz
parents:
diff changeset
7 // RUN: FileCheck --check-prefix DTORS3 %s < %t
anatofuz
parents:
diff changeset
8 // RUN: FileCheck --check-prefix DTORS4 %s < %t
anatofuz
parents:
diff changeset
9 //
anatofuz
parents:
diff changeset
10 // RUN: %clang_cc1 -emit-llvm %s -o - -mconstructor-aliases -triple=x86_64-pc-win32 -fno-rtti -std=c++11 | FileCheck --check-prefix DTORS-X64 %s
anatofuz
parents:
diff changeset
11
anatofuz
parents:
diff changeset
12 namespace basic {
anatofuz
parents:
diff changeset
13
anatofuz
parents:
diff changeset
14 class A {
anatofuz
parents:
diff changeset
15 public:
anatofuz
parents:
diff changeset
16 A() { }
anatofuz
parents:
diff changeset
17 ~A();
anatofuz
parents:
diff changeset
18 };
anatofuz
parents:
diff changeset
19
anatofuz
parents:
diff changeset
20 void no_constructor_destructor_infinite_recursion() {
anatofuz
parents:
diff changeset
21 A a;
anatofuz
parents:
diff changeset
22
anatofuz
parents:
diff changeset
23 // CHECK: define linkonce_odr dso_local x86_thiscallcc %"class.basic::A"* @"??0A@basic@@QAE@XZ"(%"class.basic::A"* returned %this) {{.*}} comdat {{.*}} {
anatofuz
parents:
diff changeset
24 // CHECK: [[THIS_ADDR:%[.0-9A-Z_a-z]+]] = alloca %"class.basic::A"*, align 4
anatofuz
parents:
diff changeset
25 // CHECK-NEXT: store %"class.basic::A"* %this, %"class.basic::A"** [[THIS_ADDR]], align 4
anatofuz
parents:
diff changeset
26 // CHECK-NEXT: [[T1:%[.0-9A-Z_a-z]+]] = load %"class.basic::A"*, %"class.basic::A"** [[THIS_ADDR]]
anatofuz
parents:
diff changeset
27 // CHECK-NEXT: ret %"class.basic::A"* [[T1]]
anatofuz
parents:
diff changeset
28 // CHECK-NEXT: }
anatofuz
parents:
diff changeset
29 }
anatofuz
parents:
diff changeset
30
anatofuz
parents:
diff changeset
31 A::~A() {
anatofuz
parents:
diff changeset
32 // Make sure that the destructor doesn't call itself:
anatofuz
parents:
diff changeset
33 // CHECK: define {{.*}} @"??1A@basic@@QAE@XZ"
anatofuz
parents:
diff changeset
34 // CHECK-NOT: call void @"??1A@basic@@QAE@XZ"
anatofuz
parents:
diff changeset
35 // CHECK: ret
anatofuz
parents:
diff changeset
36 }
anatofuz
parents:
diff changeset
37
anatofuz
parents:
diff changeset
38 struct B {
anatofuz
parents:
diff changeset
39 B();
anatofuz
parents:
diff changeset
40 };
anatofuz
parents:
diff changeset
41
anatofuz
parents:
diff changeset
42 // Tests that we can define constructors outside the class (PR12784).
anatofuz
parents:
diff changeset
43 B::B() {
anatofuz
parents:
diff changeset
44 // CHECK: define dso_local x86_thiscallcc %"struct.basic::B"* @"??0B@basic@@QAE@XZ"(%"struct.basic::B"* returned %this)
anatofuz
parents:
diff changeset
45 // CHECK: ret
anatofuz
parents:
diff changeset
46 }
anatofuz
parents:
diff changeset
47
anatofuz
parents:
diff changeset
48 struct C {
anatofuz
parents:
diff changeset
49 virtual ~C() {
anatofuz
parents:
diff changeset
50 // DTORS: define linkonce_odr dso_local x86_thiscallcc i8* @"??_GC@basic@@UAEPAXI@Z"(%"struct.basic::C"* %this, i32 %should_call_delete) {{.*}} comdat {{.*}} {
anatofuz
parents:
diff changeset
51 // DTORS: store i32 %should_call_delete, i32* %[[SHOULD_DELETE_VAR:[0-9a-z._]+]], align 4
anatofuz
parents:
diff changeset
52 // DTORS: store i8* %{{.*}}, i8** %[[RETVAL:[0-9a-z._]+]]
anatofuz
parents:
diff changeset
53 // DTORS: %[[SHOULD_DELETE_VALUE:[0-9a-z._]+]] = load i32, i32* %[[SHOULD_DELETE_VAR]]
anatofuz
parents:
diff changeset
54 // DTORS: call x86_thiscallcc void @"??1C@basic@@UAE@XZ"(%"struct.basic::C"* %[[THIS:[0-9a-z]+]])
anatofuz
parents:
diff changeset
55 // DTORS-NEXT: %[[CONDITION:[0-9]+]] = icmp eq i32 %[[SHOULD_DELETE_VALUE]], 0
anatofuz
parents:
diff changeset
56 // DTORS-NEXT: br i1 %[[CONDITION]], label %[[CONTINUE_LABEL:[0-9a-z._]+]], label %[[CALL_DELETE_LABEL:[0-9a-z._]+]]
anatofuz
parents:
diff changeset
57 //
anatofuz
parents:
diff changeset
58 // DTORS: [[CALL_DELETE_LABEL]]
anatofuz
parents:
diff changeset
59 // DTORS-NEXT: %[[THIS_AS_VOID:[0-9a-z]+]] = bitcast %"struct.basic::C"* %[[THIS]] to i8*
anatofuz
parents:
diff changeset
60 // DTORS-NEXT: call void @"??3@YAXPAX@Z"(i8* %[[THIS_AS_VOID]])
anatofuz
parents:
diff changeset
61 // DTORS-NEXT: br label %[[CONTINUE_LABEL]]
anatofuz
parents:
diff changeset
62 //
anatofuz
parents:
diff changeset
63 // DTORS: [[CONTINUE_LABEL]]
anatofuz
parents:
diff changeset
64 // DTORS-NEXT: %[[RET:.*]] = load i8*, i8** %[[RETVAL]]
anatofuz
parents:
diff changeset
65 // DTORS-NEXT: ret i8* %[[RET]]
anatofuz
parents:
diff changeset
66
anatofuz
parents:
diff changeset
67 // Check that we do the mangling correctly on x64.
anatofuz
parents:
diff changeset
68 // DTORS-X64: @"??_GC@basic@@UEAAPEAXI@Z"
anatofuz
parents:
diff changeset
69 }
anatofuz
parents:
diff changeset
70 virtual void foo();
anatofuz
parents:
diff changeset
71 };
anatofuz
parents:
diff changeset
72
anatofuz
parents:
diff changeset
73 // Emits the vftable in the output.
anatofuz
parents:
diff changeset
74 void C::foo() {}
anatofuz
parents:
diff changeset
75
anatofuz
parents:
diff changeset
76 void check_vftable_offset() {
anatofuz
parents:
diff changeset
77 C c;
anatofuz
parents:
diff changeset
78 // The vftable pointer should point at the beginning of the vftable.
anatofuz
parents:
diff changeset
79 // CHECK: [[THIS_PTR:%[0-9]+]] = bitcast %"struct.basic::C"* {{.*}} to i32 (...)***
anatofuz
parents:
diff changeset
80 // CHECK: store i32 (...)** bitcast ({ [2 x i8*] }* @"??_7C@basic@@6B@" to i32 (...)**), i32 (...)*** [[THIS_PTR]]
anatofuz
parents:
diff changeset
81 }
anatofuz
parents:
diff changeset
82
anatofuz
parents:
diff changeset
83 void call_complete_dtor(C *obj_ptr) {
anatofuz
parents:
diff changeset
84 // CHECK: define dso_local void @"?call_complete_dtor@basic@@YAXPAUC@1@@Z"(%"struct.basic::C"* %obj_ptr)
anatofuz
parents:
diff changeset
85 obj_ptr->~C();
anatofuz
parents:
diff changeset
86 // CHECK: %[[OBJ_PTR_VALUE:.*]] = load %"struct.basic::C"*, %"struct.basic::C"** %{{.*}}, align 4
anatofuz
parents:
diff changeset
87 // CHECK-NEXT: %[[PVTABLE:.*]] = bitcast %"struct.basic::C"* %[[OBJ_PTR_VALUE]] to i8* (%"struct.basic::C"*, i32)***
anatofuz
parents:
diff changeset
88 // CHECK-NEXT: %[[VTABLE:.*]] = load i8* (%"struct.basic::C"*, i32)**, i8* (%"struct.basic::C"*, i32)*** %[[PVTABLE]]
anatofuz
parents:
diff changeset
89 // CHECK-NEXT: %[[PVDTOR:.*]] = getelementptr inbounds i8* (%"struct.basic::C"*, i32)*, i8* (%"struct.basic::C"*, i32)** %[[VTABLE]], i64 0
anatofuz
parents:
diff changeset
90 // CHECK-NEXT: %[[VDTOR:.*]] = load i8* (%"struct.basic::C"*, i32)*, i8* (%"struct.basic::C"*, i32)** %[[PVDTOR]]
anatofuz
parents:
diff changeset
91 // CHECK-NEXT: call x86_thiscallcc i8* %[[VDTOR]](%"struct.basic::C"* %[[OBJ_PTR_VALUE]], i32 0)
anatofuz
parents:
diff changeset
92 // CHECK-NEXT: ret void
anatofuz
parents:
diff changeset
93 }
anatofuz
parents:
diff changeset
94
anatofuz
parents:
diff changeset
95 void call_deleting_dtor(C *obj_ptr) {
anatofuz
parents:
diff changeset
96 // CHECK: define dso_local void @"?call_deleting_dtor@basic@@YAXPAUC@1@@Z"(%"struct.basic::C"* %obj_ptr)
anatofuz
parents:
diff changeset
97 delete obj_ptr;
anatofuz
parents:
diff changeset
98 // CHECK: %[[OBJ_PTR_VALUE:.*]] = load %"struct.basic::C"*, %"struct.basic::C"** %{{.*}}, align 4
anatofuz
parents:
diff changeset
99 // CHECK: br i1 {{.*}}, label %[[DELETE_NULL:.*]], label %[[DELETE_NOTNULL:.*]]
anatofuz
parents:
diff changeset
100
anatofuz
parents:
diff changeset
101 // CHECK: [[DELETE_NOTNULL]]
anatofuz
parents:
diff changeset
102 // CHECK-NEXT: %[[PVTABLE:.*]] = bitcast %"struct.basic::C"* %[[OBJ_PTR_VALUE]] to i8* (%"struct.basic::C"*, i32)***
anatofuz
parents:
diff changeset
103 // CHECK-NEXT: %[[VTABLE:.*]] = load i8* (%"struct.basic::C"*, i32)**, i8* (%"struct.basic::C"*, i32)*** %[[PVTABLE]]
anatofuz
parents:
diff changeset
104 // CHECK-NEXT: %[[PVDTOR:.*]] = getelementptr inbounds i8* (%"struct.basic::C"*, i32)*, i8* (%"struct.basic::C"*, i32)** %[[VTABLE]], i64 0
anatofuz
parents:
diff changeset
105 // CHECK-NEXT: %[[VDTOR:.*]] = load i8* (%"struct.basic::C"*, i32)*, i8* (%"struct.basic::C"*, i32)** %[[PVDTOR]]
anatofuz
parents:
diff changeset
106 // CHECK-NEXT: call x86_thiscallcc i8* %[[VDTOR]](%"struct.basic::C"* %[[OBJ_PTR_VALUE]], i32 1)
anatofuz
parents:
diff changeset
107 // CHECK: ret void
anatofuz
parents:
diff changeset
108 }
anatofuz
parents:
diff changeset
109
anatofuz
parents:
diff changeset
110 void call_deleting_dtor_and_global_delete(C *obj_ptr) {
anatofuz
parents:
diff changeset
111 // CHECK: define dso_local void @"?call_deleting_dtor_and_global_delete@basic@@YAXPAUC@1@@Z"(%"struct.basic::C"* %obj_ptr)
anatofuz
parents:
diff changeset
112 ::delete obj_ptr;
anatofuz
parents:
diff changeset
113 // CHECK: %[[OBJ_PTR_VALUE:.*]] = load %"struct.basic::C"*, %"struct.basic::C"** %{{.*}}, align 4
anatofuz
parents:
diff changeset
114 // CHECK: br i1 {{.*}}, label %[[DELETE_NULL:.*]], label %[[DELETE_NOTNULL:.*]]
anatofuz
parents:
diff changeset
115
anatofuz
parents:
diff changeset
116 // CHECK: [[DELETE_NOTNULL]]
anatofuz
parents:
diff changeset
117 // CHECK-NEXT: %[[PVTABLE:.*]] = bitcast %"struct.basic::C"* %[[OBJ_PTR_VALUE]] to i8* (%"struct.basic::C"*, i32)***
anatofuz
parents:
diff changeset
118 // CHECK-NEXT: %[[VTABLE:.*]] = load i8* (%"struct.basic::C"*, i32)**, i8* (%"struct.basic::C"*, i32)*** %[[PVTABLE]]
anatofuz
parents:
diff changeset
119 // CHECK-NEXT: %[[PVDTOR:.*]] = getelementptr inbounds i8* (%"struct.basic::C"*, i32)*, i8* (%"struct.basic::C"*, i32)** %[[VTABLE]], i64 0
anatofuz
parents:
diff changeset
120 // CHECK-NEXT: %[[VDTOR:.*]] = load i8* (%"struct.basic::C"*, i32)*, i8* (%"struct.basic::C"*, i32)** %[[PVDTOR]]
anatofuz
parents:
diff changeset
121 // CHECK-NEXT: %[[CALL:.*]] = call x86_thiscallcc i8* %[[VDTOR]](%"struct.basic::C"* %[[OBJ_PTR_VALUE]], i32 0)
anatofuz
parents:
diff changeset
122 // CHECK-NEXT: call void @"??3@YAXPAX@Z"(i8* %[[CALL]])
anatofuz
parents:
diff changeset
123 // CHECK: ret void
anatofuz
parents:
diff changeset
124 }
anatofuz
parents:
diff changeset
125
anatofuz
parents:
diff changeset
126 struct D {
anatofuz
parents:
diff changeset
127 static int foo();
anatofuz
parents:
diff changeset
128
anatofuz
parents:
diff changeset
129 D() {
anatofuz
parents:
diff changeset
130 static int ctor_static = foo();
anatofuz
parents:
diff changeset
131 // CHECK that the static in the ctor gets mangled correctly:
anatofuz
parents:
diff changeset
132 // CHECK: @"?ctor_static@?1???0D@basic@@QAE@XZ@4HA"
anatofuz
parents:
diff changeset
133 }
anatofuz
parents:
diff changeset
134 ~D() {
anatofuz
parents:
diff changeset
135 static int dtor_static = foo();
anatofuz
parents:
diff changeset
136 // CHECK that the static in the dtor gets mangled correctly:
anatofuz
parents:
diff changeset
137 // CHECK: @"?dtor_static@?1???1D@basic@@QAE@XZ@4HA"
anatofuz
parents:
diff changeset
138 }
anatofuz
parents:
diff changeset
139 };
anatofuz
parents:
diff changeset
140
anatofuz
parents:
diff changeset
141 void use_D() { D c; }
anatofuz
parents:
diff changeset
142
anatofuz
parents:
diff changeset
143 } // end namespace basic
anatofuz
parents:
diff changeset
144
anatofuz
parents:
diff changeset
145 namespace dtor_in_second_nvbase {
anatofuz
parents:
diff changeset
146
anatofuz
parents:
diff changeset
147 struct A {
anatofuz
parents:
diff changeset
148 virtual void f(); // A needs vftable to be primary.
anatofuz
parents:
diff changeset
149 };
anatofuz
parents:
diff changeset
150 struct B {
anatofuz
parents:
diff changeset
151 virtual ~B();
anatofuz
parents:
diff changeset
152 };
anatofuz
parents:
diff changeset
153 struct C : A, B {
anatofuz
parents:
diff changeset
154 virtual ~C();
anatofuz
parents:
diff changeset
155 };
anatofuz
parents:
diff changeset
156
anatofuz
parents:
diff changeset
157 C::~C() {
anatofuz
parents:
diff changeset
158 // CHECK-LABEL: define dso_local x86_thiscallcc void @"??1C@dtor_in_second_nvbase@@UAE@XZ"
anatofuz
parents:
diff changeset
159 // CHECK: (%"struct.dtor_in_second_nvbase::C"* %this)
anatofuz
parents:
diff changeset
160 // No this adjustment!
anatofuz
parents:
diff changeset
161 // CHECK-NOT: getelementptr
anatofuz
parents:
diff changeset
162 // CHECK: load %"struct.dtor_in_second_nvbase::C"*, %"struct.dtor_in_second_nvbase::C"** %{{.*}}
anatofuz
parents:
diff changeset
163 // Now we this-adjust before calling ~B.
anatofuz
parents:
diff changeset
164 // CHECK: bitcast %"struct.dtor_in_second_nvbase::C"* %{{.*}} to i8*
anatofuz
parents:
diff changeset
165 // CHECK: getelementptr inbounds i8, i8* %{{.*}}, i32 4
anatofuz
parents:
diff changeset
166 // CHECK: bitcast i8* %{{.*}} to %"struct.dtor_in_second_nvbase::B"*
anatofuz
parents:
diff changeset
167 // CHECK: call x86_thiscallcc void @"??1B@dtor_in_second_nvbase@@UAE@XZ"
anatofuz
parents:
diff changeset
168 // CHECK: (%"struct.dtor_in_second_nvbase::B"* %{{.*}})
anatofuz
parents:
diff changeset
169 // CHECK: ret void
anatofuz
parents:
diff changeset
170 }
anatofuz
parents:
diff changeset
171
anatofuz
parents:
diff changeset
172 void foo() {
anatofuz
parents:
diff changeset
173 C c;
anatofuz
parents:
diff changeset
174 }
anatofuz
parents:
diff changeset
175 // DTORS2-LABEL: define linkonce_odr dso_local x86_thiscallcc i8* @"??_EC@dtor_in_second_nvbase@@W3AEPAXI@Z"
anatofuz
parents:
diff changeset
176 // DTORS2: (%"struct.dtor_in_second_nvbase::C"* %this, i32 %should_call_delete)
anatofuz
parents:
diff changeset
177 // Do an adjustment from B* to C*.
anatofuz
parents:
diff changeset
178 // DTORS2: getelementptr i8, i8* %{{.*}}, i32 -4
anatofuz
parents:
diff changeset
179 // DTORS2: bitcast i8* %{{.*}} to %"struct.dtor_in_second_nvbase::C"*
anatofuz
parents:
diff changeset
180 // DTORS2: %[[CALL:.*]] = tail call x86_thiscallcc i8* @"??_GC@dtor_in_second_nvbase@@UAEPAXI@Z"
anatofuz
parents:
diff changeset
181 // DTORS2: ret i8* %[[CALL]]
anatofuz
parents:
diff changeset
182
anatofuz
parents:
diff changeset
183 }
anatofuz
parents:
diff changeset
184
anatofuz
parents:
diff changeset
185 namespace test2 {
anatofuz
parents:
diff changeset
186 // Just like dtor_in_second_nvbase, except put that in a vbase of a diamond.
anatofuz
parents:
diff changeset
187
anatofuz
parents:
diff changeset
188 // C's dtor is in the non-primary base.
anatofuz
parents:
diff changeset
189 struct A { virtual void f(); };
anatofuz
parents:
diff changeset
190 struct B { virtual ~B(); };
anatofuz
parents:
diff changeset
191 struct C : A, B { virtual ~C(); int c; };
anatofuz
parents:
diff changeset
192
anatofuz
parents:
diff changeset
193 // Diamond hierarchy, with C as the shared vbase.
anatofuz
parents:
diff changeset
194 struct D : virtual C { int d; };
anatofuz
parents:
diff changeset
195 struct E : virtual C { int e; };
anatofuz
parents:
diff changeset
196 struct F : D, E { ~F(); int f; };
anatofuz
parents:
diff changeset
197
anatofuz
parents:
diff changeset
198 F::~F() {
anatofuz
parents:
diff changeset
199 // CHECK-LABEL: define dso_local x86_thiscallcc void @"??1F@test2@@UAE@XZ"(%"struct.test2::F"*{{[^,]*}})
anatofuz
parents:
diff changeset
200 // Do an adjustment from C vbase subobject to F as though F was the
anatofuz
parents:
diff changeset
201 // complete type.
anatofuz
parents:
diff changeset
202 // CHECK: getelementptr inbounds i8, i8* %{{.*}}, i32 -20
anatofuz
parents:
diff changeset
203 // CHECK: bitcast i8* %{{.*}} to %"struct.test2::F"*
anatofuz
parents:
diff changeset
204 // CHECK: store %"struct.test2::F"*
anatofuz
parents:
diff changeset
205 }
anatofuz
parents:
diff changeset
206
anatofuz
parents:
diff changeset
207 void foo() {
anatofuz
parents:
diff changeset
208 F f;
anatofuz
parents:
diff changeset
209 }
anatofuz
parents:
diff changeset
210 // DTORS3-LABEL: define linkonce_odr dso_local x86_thiscallcc void @"??_DF@test2@@QAEXXZ"({{.*}} {{.*}} comdat
anatofuz
parents:
diff changeset
211 // Do an adjustment from C* to F*.
anatofuz
parents:
diff changeset
212 // DTORS3: getelementptr i8, i8* %{{.*}}, i32 20
anatofuz
parents:
diff changeset
213 // DTORS3: bitcast i8* %{{.*}} to %"struct.test2::F"*
anatofuz
parents:
diff changeset
214 // DTORS3: call x86_thiscallcc void @"??1F@test2@@UAE@XZ"
anatofuz
parents:
diff changeset
215 // DTORS3: ret void
anatofuz
parents:
diff changeset
216
anatofuz
parents:
diff changeset
217 }
anatofuz
parents:
diff changeset
218
anatofuz
parents:
diff changeset
219 namespace constructors {
anatofuz
parents:
diff changeset
220
anatofuz
parents:
diff changeset
221 struct A {
anatofuz
parents:
diff changeset
222 A() {}
anatofuz
parents:
diff changeset
223 };
anatofuz
parents:
diff changeset
224
anatofuz
parents:
diff changeset
225 struct B : A {
anatofuz
parents:
diff changeset
226 B();
anatofuz
parents:
diff changeset
227 ~B();
anatofuz
parents:
diff changeset
228 };
anatofuz
parents:
diff changeset
229
anatofuz
parents:
diff changeset
230 B::B() {
anatofuz
parents:
diff changeset
231 // CHECK: define dso_local x86_thiscallcc %"struct.constructors::B"* @"??0B@constructors@@QAE@XZ"(%"struct.constructors::B"* returned %this)
anatofuz
parents:
diff changeset
232 // CHECK: call x86_thiscallcc %"struct.constructors::A"* @"??0A@constructors@@QAE@XZ"(%"struct.constructors::A"* %{{.*}})
anatofuz
parents:
diff changeset
233 // CHECK: ret
anatofuz
parents:
diff changeset
234 }
anatofuz
parents:
diff changeset
235
anatofuz
parents:
diff changeset
236 struct C : virtual A {
anatofuz
parents:
diff changeset
237 C();
anatofuz
parents:
diff changeset
238 };
anatofuz
parents:
diff changeset
239
anatofuz
parents:
diff changeset
240 C::C() {
anatofuz
parents:
diff changeset
241 // CHECK: define dso_local x86_thiscallcc %"struct.constructors::C"* @"??0C@constructors@@QAE@XZ"(%"struct.constructors::C"* returned %this, i32 %is_most_derived)
anatofuz
parents:
diff changeset
242 // TODO: make sure this works in the Release build too;
anatofuz
parents:
diff changeset
243 // CHECK: store i32 %is_most_derived, i32* %[[IS_MOST_DERIVED_VAR:.*]], align 4
anatofuz
parents:
diff changeset
244 // CHECK: %[[IS_MOST_DERIVED_VAL:.*]] = load i32, i32* %[[IS_MOST_DERIVED_VAR]]
anatofuz
parents:
diff changeset
245 // CHECK: %[[SHOULD_CALL_VBASE_CTORS:.*]] = icmp ne i32 %[[IS_MOST_DERIVED_VAL]], 0
anatofuz
parents:
diff changeset
246 // CHECK: br i1 %[[SHOULD_CALL_VBASE_CTORS]], label %[[INIT_VBASES:.*]], label %[[SKIP_VBASES:.*]]
anatofuz
parents:
diff changeset
247 //
anatofuz
parents:
diff changeset
248 // CHECK: [[INIT_VBASES]]
anatofuz
parents:
diff changeset
249 // CHECK-NEXT: %[[this_i8:.*]] = bitcast %"struct.constructors::C"* %{{.*}} to i8*
anatofuz
parents:
diff changeset
250 // CHECK-NEXT: %[[vbptr_off:.*]] = getelementptr inbounds i8, i8* %[[this_i8]], i32 0
anatofuz
parents:
diff changeset
251 // CHECK-NEXT: %[[vbptr:.*]] = bitcast i8* %[[vbptr_off]] to i32**
anatofuz
parents:
diff changeset
252 // CHECK-NEXT: store i32* getelementptr inbounds ([2 x i32], [2 x i32]* @"??_8C@constructors@@7B@", i32 0, i32 0), i32** %[[vbptr]]
anatofuz
parents:
diff changeset
253 // CHECK-NEXT: bitcast %"struct.constructors::C"* %{{.*}} to i8*
anatofuz
parents:
diff changeset
254 // CHECK-NEXT: getelementptr inbounds i8, i8* %{{.*}}, i32 4
anatofuz
parents:
diff changeset
255 // CHECK-NEXT: bitcast i8* %{{.*}} to %"struct.constructors::A"*
anatofuz
parents:
diff changeset
256 // CHECK-NEXT: call x86_thiscallcc %"struct.constructors::A"* @"??0A@constructors@@QAE@XZ"(%"struct.constructors::A"* %{{.*}})
anatofuz
parents:
diff changeset
257 // CHECK-NEXT: br label %[[SKIP_VBASES]]
anatofuz
parents:
diff changeset
258 //
anatofuz
parents:
diff changeset
259 // CHECK: [[SKIP_VBASES]]
anatofuz
parents:
diff changeset
260 // Class C does not define or override methods, so shouldn't change the vfptr.
anatofuz
parents:
diff changeset
261 // CHECK-NOT: @"??_7C@constructors@@6B@"
anatofuz
parents:
diff changeset
262 // CHECK: ret
anatofuz
parents:
diff changeset
263 }
anatofuz
parents:
diff changeset
264
anatofuz
parents:
diff changeset
265 void create_C() {
anatofuz
parents:
diff changeset
266 C c;
anatofuz
parents:
diff changeset
267 // CHECK: define dso_local void @"?create_C@constructors@@YAXXZ"()
anatofuz
parents:
diff changeset
268 // CHECK: call x86_thiscallcc %"struct.constructors::C"* @"??0C@constructors@@QAE@XZ"(%"struct.constructors::C"* %c, i32 1)
anatofuz
parents:
diff changeset
269 // CHECK: ret
anatofuz
parents:
diff changeset
270 }
anatofuz
parents:
diff changeset
271
anatofuz
parents:
diff changeset
272 struct D : C {
anatofuz
parents:
diff changeset
273 D();
anatofuz
parents:
diff changeset
274 };
anatofuz
parents:
diff changeset
275
anatofuz
parents:
diff changeset
276 D::D() {
anatofuz
parents:
diff changeset
277 // CHECK: define dso_local x86_thiscallcc %"struct.constructors::D"* @"??0D@constructors@@QAE@XZ"(%"struct.constructors::D"* returned %this, i32 %is_most_derived) unnamed_addr
anatofuz
parents:
diff changeset
278 // CHECK: store i32 %is_most_derived, i32* %[[IS_MOST_DERIVED_VAR:.*]], align 4
anatofuz
parents:
diff changeset
279 // CHECK: %[[IS_MOST_DERIVED_VAL:.*]] = load i32, i32* %[[IS_MOST_DERIVED_VAR]]
anatofuz
parents:
diff changeset
280 // CHECK: %[[SHOULD_CALL_VBASE_CTORS:.*]] = icmp ne i32 %[[IS_MOST_DERIVED_VAL]], 0
anatofuz
parents:
diff changeset
281 // CHECK: br i1 %[[SHOULD_CALL_VBASE_CTORS]], label %[[INIT_VBASES:.*]], label %[[SKIP_VBASES:.*]]
anatofuz
parents:
diff changeset
282 //
anatofuz
parents:
diff changeset
283 // CHECK: [[INIT_VBASES]]
anatofuz
parents:
diff changeset
284 // CHECK-NEXT: %[[this_i8:.*]] = bitcast %"struct.constructors::D"* %{{.*}} to i8*
anatofuz
parents:
diff changeset
285 // CHECK-NEXT: %[[vbptr_off:.*]] = getelementptr inbounds i8, i8* %[[this_i8]], i32 0
anatofuz
parents:
diff changeset
286 // CHECK-NEXT: %[[vbptr:.*]] = bitcast i8* %[[vbptr_off]] to i32**
anatofuz
parents:
diff changeset
287 // CHECK-NEXT: store i32* getelementptr inbounds ([2 x i32], [2 x i32]* @"??_8D@constructors@@7B@", i32 0, i32 0), i32** %[[vbptr]]
anatofuz
parents:
diff changeset
288 // CHECK-NEXT: bitcast %"struct.constructors::D"* %{{.*}} to i8*
anatofuz
parents:
diff changeset
289 // CHECK-NEXT: getelementptr inbounds i8, i8* %{{.*}}, i32 4
anatofuz
parents:
diff changeset
290 // CHECK-NEXT: bitcast i8* %{{.*}} to %"struct.constructors::A"*
anatofuz
parents:
diff changeset
291 // CHECK-NEXT: call x86_thiscallcc %"struct.constructors::A"* @"??0A@constructors@@QAE@XZ"(%"struct.constructors::A"* %{{.*}})
anatofuz
parents:
diff changeset
292 // CHECK-NEXT: br label %[[SKIP_VBASES]]
anatofuz
parents:
diff changeset
293 //
anatofuz
parents:
diff changeset
294 // CHECK: [[SKIP_VBASES]]
anatofuz
parents:
diff changeset
295 // CHECK: call x86_thiscallcc %"struct.constructors::C"* @"??0C@constructors@@QAE@XZ"(%"struct.constructors::C"* %{{.*}}, i32 0)
anatofuz
parents:
diff changeset
296 // CHECK: ret
anatofuz
parents:
diff changeset
297 }
anatofuz
parents:
diff changeset
298
anatofuz
parents:
diff changeset
299 struct E : virtual C {
anatofuz
parents:
diff changeset
300 E();
anatofuz
parents:
diff changeset
301 };
anatofuz
parents:
diff changeset
302
anatofuz
parents:
diff changeset
303 E::E() {
anatofuz
parents:
diff changeset
304 // CHECK: define dso_local x86_thiscallcc %"struct.constructors::E"* @"??0E@constructors@@QAE@XZ"(%"struct.constructors::E"* returned %this, i32 %is_most_derived) unnamed_addr
anatofuz
parents:
diff changeset
305 // CHECK: store i32 %is_most_derived, i32* %[[IS_MOST_DERIVED_VAR:.*]], align 4
anatofuz
parents:
diff changeset
306 // CHECK: %[[IS_MOST_DERIVED_VAL:.*]] = load i32, i32* %[[IS_MOST_DERIVED_VAR]]
anatofuz
parents:
diff changeset
307 // CHECK: %[[SHOULD_CALL_VBASE_CTORS:.*]] = icmp ne i32 %[[IS_MOST_DERIVED_VAL]], 0
anatofuz
parents:
diff changeset
308 // CHECK: br i1 %[[SHOULD_CALL_VBASE_CTORS]], label %[[INIT_VBASES:.*]], label %[[SKIP_VBASES:.*]]
anatofuz
parents:
diff changeset
309 //
anatofuz
parents:
diff changeset
310 // CHECK: [[INIT_VBASES]]
anatofuz
parents:
diff changeset
311 // CHECK-NEXT: %[[this_i8:.*]] = bitcast %"struct.constructors::E"* %{{.*}} to i8*
anatofuz
parents:
diff changeset
312 // CHECK-NEXT: %[[offs:.*]] = getelementptr inbounds i8, i8* %[[this_i8]], i32 0
anatofuz
parents:
diff changeset
313 // CHECK-NEXT: %[[vbptr_E:.*]] = bitcast i8* %[[offs]] to i32**
anatofuz
parents:
diff changeset
314 // CHECK-NEXT: store i32* getelementptr inbounds ([3 x i32], [3 x i32]* @"??_8E@constructors@@7B01@@", i32 0, i32 0), i32** %[[vbptr_E]]
anatofuz
parents:
diff changeset
315 // CHECK-NEXT: %[[offs:.*]] = getelementptr inbounds i8, i8* %[[this_i8]], i32 4
anatofuz
parents:
diff changeset
316 // CHECK-NEXT: %[[vbptr_C:.*]] = bitcast i8* %[[offs]] to i32**
anatofuz
parents:
diff changeset
317 // CHECK-NEXT: store i32* getelementptr inbounds ([2 x i32], [2 x i32]* @"??_8E@constructors@@7BC@1@@", i32 0, i32 0), i32** %[[vbptr_C]]
anatofuz
parents:
diff changeset
318 // CHECK-NEXT: bitcast %"struct.constructors::E"* %{{.*}} to i8*
anatofuz
parents:
diff changeset
319 // CHECK-NEXT: getelementptr inbounds i8, i8* %{{.*}}, i32 4
anatofuz
parents:
diff changeset
320 // CHECK-NEXT: bitcast i8* %{{.*}} to %"struct.constructors::A"*
anatofuz
parents:
diff changeset
321 // CHECK-NEXT: call x86_thiscallcc %"struct.constructors::A"* @"??0A@constructors@@QAE@XZ"(%"struct.constructors::A"* %{{.*}})
anatofuz
parents:
diff changeset
322 // CHECK: call x86_thiscallcc %"struct.constructors::C"* @"??0C@constructors@@QAE@XZ"(%"struct.constructors::C"* %{{.*}}, i32 0)
anatofuz
parents:
diff changeset
323 // CHECK-NEXT: br label %[[SKIP_VBASES]]
anatofuz
parents:
diff changeset
324 //
anatofuz
parents:
diff changeset
325 // CHECK: [[SKIP_VBASES]]
anatofuz
parents:
diff changeset
326 // CHECK: ret
anatofuz
parents:
diff changeset
327 }
anatofuz
parents:
diff changeset
328
anatofuz
parents:
diff changeset
329 // PR16735 - even abstract classes should have a constructor emitted.
anatofuz
parents:
diff changeset
330 struct F {
anatofuz
parents:
diff changeset
331 F();
anatofuz
parents:
diff changeset
332 virtual void f() = 0;
anatofuz
parents:
diff changeset
333 };
anatofuz
parents:
diff changeset
334
anatofuz
parents:
diff changeset
335 F::F() {}
anatofuz
parents:
diff changeset
336 // CHECK: define dso_local x86_thiscallcc %"struct.constructors::F"* @"??0F@constructors@@QAE@XZ"
anatofuz
parents:
diff changeset
337
anatofuz
parents:
diff changeset
338 } // end namespace constructors
anatofuz
parents:
diff changeset
339
anatofuz
parents:
diff changeset
340 namespace dtors {
anatofuz
parents:
diff changeset
341
anatofuz
parents:
diff changeset
342 struct A {
anatofuz
parents:
diff changeset
343 ~A();
anatofuz
parents:
diff changeset
344 };
anatofuz
parents:
diff changeset
345
anatofuz
parents:
diff changeset
346 void call_nv_complete(A *a) {
anatofuz
parents:
diff changeset
347 a->~A();
anatofuz
parents:
diff changeset
348 // CHECK: define dso_local void @"?call_nv_complete@dtors@@YAXPAUA@1@@Z"
anatofuz
parents:
diff changeset
349 // CHECK: call x86_thiscallcc void @"??1A@dtors@@QAE@XZ"
anatofuz
parents:
diff changeset
350 // CHECK: ret
anatofuz
parents:
diff changeset
351 }
anatofuz
parents:
diff changeset
352
anatofuz
parents:
diff changeset
353 // CHECK: declare dso_local x86_thiscallcc void @"??1A@dtors@@QAE@XZ"
anatofuz
parents:
diff changeset
354
anatofuz
parents:
diff changeset
355 // Now try some virtual bases, where we need the complete dtor.
anatofuz
parents:
diff changeset
356
anatofuz
parents:
diff changeset
357 struct B : virtual A { ~B(); };
anatofuz
parents:
diff changeset
358 struct C : virtual A { ~C(); };
anatofuz
parents:
diff changeset
359 struct D : B, C { ~D(); };
anatofuz
parents:
diff changeset
360
anatofuz
parents:
diff changeset
361 void call_vbase_complete(D *d) {
anatofuz
parents:
diff changeset
362 d->~D();
anatofuz
parents:
diff changeset
363 // CHECK: define dso_local void @"?call_vbase_complete@dtors@@YAXPAUD@1@@Z"
anatofuz
parents:
diff changeset
364 // CHECK: call x86_thiscallcc void @"??_DD@dtors@@QAEXXZ"(%"struct.dtors::D"* %{{[^,]+}})
anatofuz
parents:
diff changeset
365 // CHECK: ret
anatofuz
parents:
diff changeset
366 }
anatofuz
parents:
diff changeset
367
anatofuz
parents:
diff changeset
368 // The complete dtor should call the base dtors for D and the vbase A (once).
anatofuz
parents:
diff changeset
369 // CHECK: define linkonce_odr dso_local x86_thiscallcc void @"??_DD@dtors@@QAEXXZ"({{.*}}) {{.*}} comdat
anatofuz
parents:
diff changeset
370 // CHECK-NOT: call
anatofuz
parents:
diff changeset
371 // CHECK: call x86_thiscallcc void @"??1D@dtors@@QAE@XZ"
anatofuz
parents:
diff changeset
372 // CHECK-NOT: call
anatofuz
parents:
diff changeset
373 // CHECK: call x86_thiscallcc void @"??1A@dtors@@QAE@XZ"
anatofuz
parents:
diff changeset
374 // CHECK-NOT: call
anatofuz
parents:
diff changeset
375 // CHECK: ret
anatofuz
parents:
diff changeset
376
anatofuz
parents:
diff changeset
377 void destroy_d_complete() {
anatofuz
parents:
diff changeset
378 D d;
anatofuz
parents:
diff changeset
379 // CHECK: define dso_local void @"?destroy_d_complete@dtors@@YAXXZ"
anatofuz
parents:
diff changeset
380 // CHECK: call x86_thiscallcc void @"??_DD@dtors@@QAEXXZ"(%"struct.dtors::D"* %{{[^,]+}})
anatofuz
parents:
diff changeset
381 // CHECK: ret
anatofuz
parents:
diff changeset
382 }
anatofuz
parents:
diff changeset
383
anatofuz
parents:
diff changeset
384 // FIXME: Clang manually inlines the deletion, so we don't get a call to the
anatofuz
parents:
diff changeset
385 // deleting dtor (_G). The only way to call deleting dtors currently is through
anatofuz
parents:
diff changeset
386 // a vftable.
anatofuz
parents:
diff changeset
387 void call_nv_deleting_dtor(D *d) {
anatofuz
parents:
diff changeset
388 delete d;
anatofuz
parents:
diff changeset
389 // CHECK: define dso_local void @"?call_nv_deleting_dtor@dtors@@YAXPAUD@1@@Z"
anatofuz
parents:
diff changeset
390 // CHECK: call x86_thiscallcc void @"??_DD@dtors@@QAEXXZ"(%"struct.dtors::D"* %{{[^,]+}})
anatofuz
parents:
diff changeset
391 // CHECK: call void @"??3@YAXPAX@Z"
anatofuz
parents:
diff changeset
392 // CHECK: ret
anatofuz
parents:
diff changeset
393 }
anatofuz
parents:
diff changeset
394
anatofuz
parents:
diff changeset
395 }
anatofuz
parents:
diff changeset
396
anatofuz
parents:
diff changeset
397 namespace test1 {
anatofuz
parents:
diff changeset
398 struct A { };
anatofuz
parents:
diff changeset
399 struct B : virtual A {
anatofuz
parents:
diff changeset
400 B(int *a);
anatofuz
parents:
diff changeset
401 B(const char *a, ...);
anatofuz
parents:
diff changeset
402 __cdecl B(short *a);
anatofuz
parents:
diff changeset
403 };
anatofuz
parents:
diff changeset
404 B::B(int *a) {}
anatofuz
parents:
diff changeset
405 B::B(const char *a, ...) {}
anatofuz
parents:
diff changeset
406 B::B(short *a) {}
anatofuz
parents:
diff changeset
407 // CHECK: define dso_local x86_thiscallcc %"struct.test1::B"* @"??0B@test1@@QAE@PAH@Z"
anatofuz
parents:
diff changeset
408 // CHECK: (%"struct.test1::B"* returned %this, i32* %a, i32 %is_most_derived)
anatofuz
parents:
diff changeset
409 // CHECK: define dso_local %"struct.test1::B"* @"??0B@test1@@QAA@PBDZZ"
anatofuz
parents:
diff changeset
410 // CHECK: (%"struct.test1::B"* returned %this, i32 %is_most_derived, i8* %a, ...)
anatofuz
parents:
diff changeset
411 // CHECK: define dso_local x86_thiscallcc %"struct.test1::B"* @"??0B@test1@@QAE@PAF@Z"
anatofuz
parents:
diff changeset
412 // CHECK: (%"struct.test1::B"* returned %this, i16* %a, i32 %is_most_derived)
anatofuz
parents:
diff changeset
413
anatofuz
parents:
diff changeset
414 void construct_b() {
anatofuz
parents:
diff changeset
415 int a;
anatofuz
parents:
diff changeset
416 B b1(&a);
anatofuz
parents:
diff changeset
417 B b2("%d %d", 1, 2);
anatofuz
parents:
diff changeset
418 }
anatofuz
parents:
diff changeset
419 // CHECK-LABEL: define dso_local void @"?construct_b@test1@@YAXXZ"()
anatofuz
parents:
diff changeset
420 // CHECK: call x86_thiscallcc %"struct.test1::B"* @"??0B@test1@@QAE@PAH@Z"
anatofuz
parents:
diff changeset
421 // CHECK: (%"struct.test1::B"* {{.*}}, i32* {{.*}}, i32 1)
anatofuz
parents:
diff changeset
422 // CHECK: call %"struct.test1::B"* (%"struct.test1::B"*, i32, i8*, ...) @"??0B@test1@@QAA@PBDZZ"
anatofuz
parents:
diff changeset
423 // CHECK: (%"struct.test1::B"* {{.*}}, i32 1, i8* {{.*}}, i32 1, i32 2)
anatofuz
parents:
diff changeset
424 }
anatofuz
parents:
diff changeset
425
anatofuz
parents:
diff changeset
426 namespace implicit_copy_vtable {
anatofuz
parents:
diff changeset
427 // This was a crash that only reproduced in ABIs without key functions.
anatofuz
parents:
diff changeset
428 struct ImplicitCopy {
anatofuz
parents:
diff changeset
429 // implicit copy ctor
anatofuz
parents:
diff changeset
430 virtual ~ImplicitCopy();
anatofuz
parents:
diff changeset
431 };
anatofuz
parents:
diff changeset
432 void CreateCopy(ImplicitCopy *a) {
anatofuz
parents:
diff changeset
433 new ImplicitCopy(*a);
anatofuz
parents:
diff changeset
434 }
anatofuz
parents:
diff changeset
435 // CHECK: store {{.*}} @"??_7ImplicitCopy@implicit_copy_vtable@@6B@"
anatofuz
parents:
diff changeset
436
anatofuz
parents:
diff changeset
437 struct MoveOnly {
anatofuz
parents:
diff changeset
438 MoveOnly(MoveOnly &&o) = default;
anatofuz
parents:
diff changeset
439 virtual ~MoveOnly();
anatofuz
parents:
diff changeset
440 };
anatofuz
parents:
diff changeset
441 MoveOnly &&f();
anatofuz
parents:
diff changeset
442 void g() { new MoveOnly(f()); }
anatofuz
parents:
diff changeset
443 // CHECK: store {{.*}} @"??_7MoveOnly@implicit_copy_vtable@@6B@"
anatofuz
parents:
diff changeset
444 }
anatofuz
parents:
diff changeset
445
anatofuz
parents:
diff changeset
446 namespace delegating_ctor {
anatofuz
parents:
diff changeset
447 struct Y {};
anatofuz
parents:
diff changeset
448 struct X : virtual Y {
anatofuz
parents:
diff changeset
449 X(int);
anatofuz
parents:
diff changeset
450 X();
anatofuz
parents:
diff changeset
451 };
anatofuz
parents:
diff changeset
452 X::X(int) : X() {}
anatofuz
parents:
diff changeset
453 }
anatofuz
parents:
diff changeset
454 // CHECK: define dso_local x86_thiscallcc %"struct.delegating_ctor::X"* @"??0X@delegating_ctor@@QAE@H@Z"(
anatofuz
parents:
diff changeset
455 // CHECK: %[[is_most_derived_addr:.*]] = alloca i32, align 4
anatofuz
parents:
diff changeset
456 // CHECK: store i32 %is_most_derived, i32* %[[is_most_derived_addr]]
anatofuz
parents:
diff changeset
457 // CHECK: %[[is_most_derived:.*]] = load i32, i32* %[[is_most_derived_addr]]
anatofuz
parents:
diff changeset
458 // CHECK: call x86_thiscallcc {{.*}}* @"??0X@delegating_ctor@@QAE@XZ"({{.*}} i32 %[[is_most_derived]])
anatofuz
parents:
diff changeset
459
anatofuz
parents:
diff changeset
460 // Dtor thunks for classes in anonymous namespaces should be internal, not
anatofuz
parents:
diff changeset
461 // linkonce_odr.
anatofuz
parents:
diff changeset
462 namespace {
anatofuz
parents:
diff changeset
463 struct A {
anatofuz
parents:
diff changeset
464 virtual ~A() { }
anatofuz
parents:
diff changeset
465 };
anatofuz
parents:
diff changeset
466 }
anatofuz
parents:
diff changeset
467 void *getA() {
anatofuz
parents:
diff changeset
468 return (void*)new A();
anatofuz
parents:
diff changeset
469 }
anatofuz
parents:
diff changeset
470 // CHECK: define internal x86_thiscallcc i8* @"??_GA@?A0x{{[^@]*}}@@UAEPAXI@Z"
anatofuz
parents:
diff changeset
471 // CHECK: (%"struct.(anonymous namespace)::A"* %this, i32 %should_call_delete)
anatofuz
parents:
diff changeset
472 // CHECK: define internal x86_thiscallcc void @"??1A@?A0x{{[^@]*}}@@UAE@XZ"
anatofuz
parents:
diff changeset
473 // CHECK: (%"struct.(anonymous namespace)::A"* %this)
anatofuz
parents:
diff changeset
474
anatofuz
parents:
diff changeset
475 // Check that we correctly transform __stdcall to __thiscall for ctors and
anatofuz
parents:
diff changeset
476 // dtors.
anatofuz
parents:
diff changeset
477 class G {
anatofuz
parents:
diff changeset
478 public:
anatofuz
parents:
diff changeset
479 __stdcall G() {};
anatofuz
parents:
diff changeset
480 // DTORS4: define linkonce_odr dso_local x86_thiscallcc %class.G* @"??0G@@QAE@XZ"
anatofuz
parents:
diff changeset
481 __stdcall ~G() {};
anatofuz
parents:
diff changeset
482 // DTORS4: define linkonce_odr dso_local x86_thiscallcc void @"??1G@@QAE@XZ"
anatofuz
parents:
diff changeset
483 };
anatofuz
parents:
diff changeset
484
anatofuz
parents:
diff changeset
485 extern void testG() {
anatofuz
parents:
diff changeset
486 G g;
anatofuz
parents:
diff changeset
487 }