1
- // RUN: %clang_cc1 %s -triple=x86_64-pc-linux-gnu -munwind-tables -emit-llvm -o - | FileCheck --check-prefix=CHECK --check-prefix=CHECK-NONOPT %s
2
- // RUN: %clang_cc1 %s -triple=x86_64-pc-linux-gnu -debug-info-kind=standalone -dwarf-version=5 -munwind-tables -emit-llvm -o - | FileCheck --check-prefix=CHECK --check-prefix=CHECK-NONOPT --check-prefix=CHECK-DBG %s
3
- // RUN: %clang_cc1 %s -triple=x86_64-pc-linux-gnu -munwind-tables -emit-llvm -o - -O1 -disable-llvm-passes | FileCheck --check-prefix=CHECK --check-prefix=CHECK-OPT %s
1
+ // Sparc64 doesn't support musttail (yet), so it uses method cloning for
2
+ // variadic thunks. Use it for testing.
3
+ // RUN: %clang_cc1 %s -triple=sparc64-pc-linux-gnu -munwind-tables -emit-llvm -o - \
4
+ // RUN: | FileCheck --check-prefixes=CHECK,CHECK-CLONE,CHECK-NONOPT %s
5
+ // RUN: %clang_cc1 %s -triple=sparc64-pc-linux-gnu -debug-info-kind=standalone -dwarf-version=5 -munwind-tables -emit-llvm -o - \
6
+ // RUN: | FileCheck --check-prefixes=CHECK,CHECK-CLONE,CHECK-NONOPT,CHECK-DBG %s
7
+ // RUN: %clang_cc1 %s -triple=sparc64-pc-linux-gnu -munwind-tables -emit-llvm -o - -O1 -disable-llvm-passes \
8
+ // RUN: | FileCheck --check-prefixes=CHECK,CHECK-CLONE,CHECK-OPT %s
9
+
10
+ // Test x86_64, which uses musttail for variadic thunks.
11
+ // RUN: %clang_cc1 %s -triple=x86_64-pc-linux-gnu -munwind-tables -emit-llvm -o - -O1 -disable-llvm-passes \
12
+ // RUN: | FileCheck --check-prefixes=CHECK,CHECK-TAIL,CHECK-OPT %s
13
+
14
+ // Finally, reuse these tests for the MS ABI.
15
+ // RUN: %clang_cc1 %s -triple=x86_64-windows-msvc -munwind-tables -emit-llvm -o - -O1 -disable-llvm-passes \
16
+ // RUN: | FileCheck --check-prefixes=WIN64 %s
17
+
4
18
5
19
namespace Test1 {
6
20
@@ -23,6 +37,11 @@ struct C : A, B {
23
37
// CHECK-LABEL: define void @_ZThn8_N5Test11C1fEv(
24
38
// CHECK-DBG-NOT: dbg.declare
25
39
// CHECK: ret void
40
+ //
41
+ // WIN64-LABEL: define dso_local void @"?f@C@Test1@@UEAAXXZ"(
42
+ // WIN64-LABEL: define linkonce_odr dso_local void @"?f@C@Test1@@W7EAAXXZ"(
43
+ // WIN64: getelementptr i8, i8* {{.*}}, i32 -8
44
+ // WIN64: ret void
26
45
void C::f () { }
27
46
28
47
}
@@ -45,6 +64,10 @@ struct B : virtual A {
45
64
// CHECK: ret void
46
65
void B::f () { }
47
66
67
+ // No thunk is used for this case in the MS ABI.
68
+ // WIN64-LABEL: define dso_local void @"?f@B@Test2@@UEAAXXZ"(
69
+ // WIN64-NOT: define {{.*}} void @"?f@B@Test2
70
+
48
71
}
49
72
50
73
namespace Test3 {
@@ -65,6 +88,7 @@ struct B : A {
65
88
};
66
89
67
90
// CHECK: define %{{.*}}* @_ZTch0_v0_n24_N5Test31B1fEv(
91
+ // WIN64: define weak_odr dso_local %{{.*}} @"?f@B@Test3@@QEAAPEAUV1@2@XZ"(
68
92
V2 *B::f () { return 0 ; }
69
93
70
94
}
@@ -92,6 +116,10 @@ struct __attribute__((visibility("protected"))) C : A, B {
92
116
// CHECK: ret void
93
117
void C::f () { }
94
118
119
+ // Visibility doesn't matter on COFF, but whatever. We could add an ELF test
120
+ // mode later.
121
+ // WIN64-LABEL: define protected void @"?f@C@Test4@@UEAAXXZ"(
122
+ // WIN64-LABEL: define linkonce_odr protected void @"?f@C@Test4@@W7EAAXXZ"(
95
123
}
96
124
97
125
// Check that the thunk gets internal linkage.
@@ -119,6 +147,8 @@ namespace Test4B {
119
147
c.f ();
120
148
}
121
149
}
150
+ // Not sure why this isn't delayed like in Itanium.
151
+ // WIN64-LABEL: define internal void @"?f@C@?A0xAEF74CE7@Test4B@@UEAAXXZ"(
122
152
123
153
namespace Test5 {
124
154
@@ -134,6 +164,7 @@ struct B : virtual A {
134
164
void f (B b) {
135
165
b.f ();
136
166
}
167
+ // No thunk in MS ABI in this case.
137
168
}
138
169
139
170
namespace Test6 {
@@ -178,6 +209,10 @@ namespace Test6 {
178
209
// CHECK: {{call void @_ZN5Test66Thunks1fEv.*sret}}
179
210
// CHECK: ret void
180
211
X Thunks::f () { return X (); }
212
+
213
+ // WIN64-LABEL: define linkonce_odr dso_local void @"?f@Thunks@Test6@@WBA@EAA?AUX@2@XZ"({{.*}} sret %{{.*}})
214
+ // WIN64-NOT: memcpy
215
+ // WIN64: tail call void @"?f@Thunks@Test6@@UEAA?AUX@2@XZ"({{.*}} sret %{{.*}})
181
216
}
182
217
183
218
namespace Test7 {
@@ -224,6 +259,8 @@ namespace Test7 {
224
259
// CHECK-NOT: memcpy
225
260
// CHECK: ret void
226
261
void testD () { D d; }
262
+
263
+ // MS C++ ABI doesn't use a thunk, so this case isn't interesting.
227
264
}
228
265
229
266
namespace Test8 {
@@ -241,6 +278,8 @@ namespace Test8 {
241
278
// CHECK-NOT: memcpy
242
279
// CHECK: ret void
243
280
void C::bar (NonPOD var) {}
281
+
282
+ // MS C++ ABI doesn't use a thunk, so this case isn't interesting.
244
283
}
245
284
246
285
// PR7241: Emitting thunks for a method shouldn't require the vtable for
@@ -287,6 +326,16 @@ namespace Test11 {
287
326
// CHECK: define {{.*}} @_ZTch0_v0_n32_N6Test111C1fEv(
288
327
// CHECK-DBG-NOT: dbg.declare
289
328
// CHECK: ret
329
+
330
+ // WIN64-LABEL: define dso_local %{{.*}}* @"?f@C@Test11@@UEAAPEAU12@XZ"(i8*
331
+
332
+ // WIN64-LABEL: define weak_odr dso_local %{{.*}}* @"?f@C@Test11@@QEAAPEAUA@2@XZ"(i8*
333
+ // WIN64: call %{{.*}}* @"?f@C@Test11@@UEAAPEAU12@XZ"(i8* %{{.*}})
334
+ //
335
+ // Match the vbtable return adjustment.
336
+ // WIN64: load i32*, i32** %{{[^,]*}}, align 8
337
+ // WIN64: getelementptr inbounds i32, i32* %{{[^,]*}}, i32 1
338
+ // WIN64: load i32, i32* %{{[^,]*}}, align 4
290
339
}
291
340
292
341
// Varargs thunk test.
@@ -301,7 +350,8 @@ namespace Test12 {
301
350
virtual void c ();
302
351
virtual C* f (int x, ...);
303
352
};
304
- C* C::f (int x, ...) { return this ; }
353
+ C* makeC ();
354
+ C* C::f (int x, ...) { return makeC (); }
305
355
306
356
// C::f
307
357
// CHECK: define {{.*}} @_ZN6Test121C1fEiz
@@ -312,6 +362,28 @@ namespace Test12 {
312
362
// CHECK-DBG-NOT: dbg.declare
313
363
// CHECK: getelementptr inbounds i8, i8* {{.*}}, i64 -8
314
364
// CHECK: getelementptr inbounds i8, i8* {{.*}}, i64 8
365
+
366
+ // The vtable layout goes:
367
+ // C vtable in A:
368
+ // - f impl, no adjustment
369
+ // C vtable in B:
370
+ // - f thunk 2, covariant, clone
371
+ // - f thunk 2, musttail this adjust to impl
372
+ // FIXME: The weak_odr linkage is probably not necessary and just an artifact
373
+ // of Itanium ABI details.
374
+ // WIN64-LABEL: define dso_local {{.*}} @"?f@C@Test12@@UEAAPEAU12@HZZ"(
375
+ // WIN64: call %{{.*}}* @"?makeC@Test12@@YAPEAUC@1@XZ"()
376
+ //
377
+ // This thunk needs return adjustment, clone.
378
+ // WIN64-LABEL: define weak_odr dso_local {{.*}} @"?f@C@Test12@@W7EAAPEAUB@2@HZZ"(
379
+ // WIN64: call %{{.*}}* @"?makeC@Test12@@YAPEAUC@1@XZ"()
380
+ // WIN64: getelementptr inbounds i8, i8* %{{.*}}, i32 8
381
+ //
382
+ // Musttail call back to the A implementation after this adjustment from B to A.
383
+ // WIN64-LABEL: define linkonce_odr dso_local %{{.*}}* @"?f@C@Test12@@W7EAAPEAU12@HZZ"(
384
+ // WIN64: getelementptr i8, i8* %{{[^,]*}}, i32 -8
385
+ // WIN64: musttail call {{.*}} @"?f@C@Test12@@UEAAPEAU12@HZZ"(
386
+ C c;
315
387
}
316
388
317
389
// PR13832
@@ -339,6 +411,17 @@ namespace Test13 {
339
411
// CHECK: getelementptr inbounds i8, i8* {{.*}}, i64 -24
340
412
// CHECK: getelementptr inbounds i8, i8* {{.*}}, i64 8
341
413
// CHECK: ret %"struct.Test13::D"*
414
+
415
+ // WIN64-LABEL: define weak_odr dso_local dereferenceable(32) %"struct.Test13::D"* @"?foo1@D@Test13@@$4PPPPPPPE@A@EAAAEAUB1@2@XZ"(
416
+ // This adjustment.
417
+ // WIN64: getelementptr inbounds i8, i8* {{.*}}, i64 -12
418
+ // Call implementation.
419
+ // WIN64: call {{.*}} @"?foo1@D@Test13@@UEAAAEAU12@XZ"(i8* {{.*}})
420
+ // Virtual + nonvirtual return adjustment.
421
+ // WIN64: load i32*, i32** %{{[^,]*}}, align 8
422
+ // WIN64: getelementptr inbounds i32, i32* %{{[^,]*}}, i32 1
423
+ // WIN64: load i32, i32* %{{[^,]*}}, align 4
424
+ // WIN64: getelementptr inbounds i8, i8* %{{[^,]*}}, i32 %{{[^,]*}}
342
425
}
343
426
344
427
namespace Test14 {
@@ -374,9 +457,16 @@ namespace Test15 {
374
457
void C::c () {}
375
458
376
459
// C::c
377
- // CHECK: declare void @_ZN6Test151C1fEiz
460
+ // CHECK-CLONE : declare void @_ZN6Test151C1fEiz
378
461
// non-virtual thunk to C::f
379
- // CHECK: declare void @_ZThn8_N6Test151C1fEiz
462
+ // CHECK-CLONE: declare void @_ZThn8_N6Test151C1fEiz
463
+
464
+ // If we have musttail, then we emit the thunk as available_externally.
465
+ // CHECK-TAIL: declare void @_ZN6Test151C1fEiz
466
+ // CHECK-TAIL: define available_externally void @_ZThn8_N6Test151C1fEiz({{.*}})
467
+ // CHECK-TAIL: musttail call void (%"struct.Test15::C"*, i32, ...) @_ZN6Test151C1fEiz({{.*}}, ...)
468
+
469
+ // MS C++ ABI doesn't use a thunk, so this case isn't interesting.
380
470
}
381
471
382
472
namespace Test16 {
@@ -398,6 +488,33 @@ D::~D() {}
398
488
// CHECK: ret void
399
489
}
400
490
491
+ namespace Test17 {
492
+ class A {
493
+ virtual void f (const char *, ...);
494
+ };
495
+ class B {
496
+ virtual void f (const char *, ...);
497
+ };
498
+ class C : A, B {
499
+ virtual void anchor ();
500
+ void f (const char *, ...) override ;
501
+ };
502
+ // Key method and object anchor vtable for Itanium and MSVC.
503
+ void C::anchor () {}
504
+ C c;
505
+
506
+ // CHECK-CLONE-LABEL: declare void @_ZThn8_N6Test171C1fEPKcz(
507
+
508
+ // CHECK-TAIL-LABEL: define available_externally void @_ZThn8_N6Test171C1fEPKcz(
509
+ // CHECK-TAIL: getelementptr inbounds i8, i8* %{{.*}}, i64 -8
510
+ // CHECK-TAIL: musttail call {{.*}} @_ZN6Test171C1fEPKcz({{.*}}, ...)
511
+
512
+ // MSVC-LABEL: define linkonce_odr dso_local void @"?f@C@Test17@@G7EAAXPEBDZZ"
513
+ // MSVC-SAME: (%"class.Test17::C"* %this, i8* %[[ARG:[^,]+]], ...)
514
+ // MSVC: getelementptr i8, i8* %{{.*}}, i32 -8
515
+ // MSVC: musttail call void (%"class.Test17::C"*, i8*, ...) @"?f@C@Test17@@EEAAXPEBDZZ"(%"class.Test17::C"* %{{.*}}, i8* %[[ARG]], ...)
516
+ }
517
+
401
518
/* *** The following has to go at the end of the file ****/
402
519
403
520
// checking without opt
@@ -421,5 +538,9 @@ D::~D() {}
421
538
// CHECK-OPT-LABEL: define linkonce_odr void @_ZN6Test101C3fooEv
422
539
// CHECK-OPT-LABEL: define linkonce_odr void @_ZThn8_N6Test101C3fooEv
423
540
541
+ // This is from Test10:
542
+ // WIN64-LABEL: define linkonce_odr dso_local void @"?foo@C@Test10@@UEAAXXZ"(
543
+ // WIN64-LABEL: define linkonce_odr dso_local void @"?foo@C@Test10@@W7EAAXXZ"(
544
+
424
545
// CHECK-NONOPT: attributes [[NUW]] = { noinline nounwind optnone uwtable{{.*}} }
425
546
// CHECK-OPT: attributes [[NUW]] = { nounwind uwtable{{.*}} }
0 commit comments