Skip to content

Commit e1f3c4a

Browse files
authored
Add an IR-level testcase to exercise LLVM IR VFE using thunks (cross-module vcalls) (swiftlang#39526)
1 parent e405a9f commit e1f3c4a

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Tests that under -enable-llvm-vfe, virtual function calls to classes defined
2+
// by other modules are using thunk calls (instead of direct vtable loads).
3+
4+
// RUN: %empty-directory(%t)
5+
// RUN: %target-build-swift -Xfrontend -disable-objc-interop -Xfrontend -enable-llvm-vfe -parse-as-library %s -DLIBRARY -module-name Library -emit-module -o %t/Library.swiftmodule
6+
// RUN: %target-build-swift -Xfrontend -disable-objc-interop -Xfrontend -enable-llvm-vfe -parse-as-library %s -DCLIENT -module-name Main -I%t -emit-ir -o - | %FileCheck %s
7+
8+
#if LIBRARY
9+
10+
public class MyLibraryClass {
11+
public func foo() { }
12+
}
13+
14+
#endif
15+
16+
#if CLIENT
17+
18+
import Library
19+
20+
public class MyLocalClass {
21+
public func bar() { }
22+
}
23+
24+
func func1(o: MyLocalClass) {
25+
// CHECK: define hidden swiftcc void @"$s4Main5func11oyAA12MyLocalClassC_tF"(%T4Main12MyLocalClassC* %0)
26+
o.bar()
27+
// CHECK: [[SLOT:%.*]] = getelementptr inbounds void (%T4Main12MyLocalClassC*)*, void (%T4Main12MyLocalClassC*)** {{.*}}, {{i64|i32}} {{.*}}
28+
// CHECK: [[SLOTASPTR:%.*]] = bitcast void (%T4Main12MyLocalClassC*)** [[SLOT]] to i8*
29+
// CHECK: call { i8*, i1 } @llvm.type.checked.load(i8* [[SLOTASPTR]], i32 0, metadata !"$s4Main12MyLocalClassC3baryyFTq")
30+
31+
// CHECK: ret void
32+
}
33+
34+
func func2(o: MyLibraryClass) {
35+
// CHECK: define hidden swiftcc void @"$s4Main5func21oy7Library02MyC5ClassC_tF"(%T7Library02MyA5ClassC* %0)
36+
o.foo()
37+
// CHECK: call swiftcc void @"$s7Library02MyA5ClassC3fooyyFTj"
38+
39+
// CHECK-NOT: @llvm.type.checked.load
40+
// CHECK: ret void
41+
}
42+
43+
#endif

0 commit comments

Comments
 (0)