Skip to content

Commit 5d23a4d

Browse files
authored
Merge pull request #78972 from eeckstein/fix-cmo
embedded: make sure to serialize vtable methods with the right linkage
2 parents 0d81606 + 3e4a4d6 commit 5d23a4d

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

lib/SILOptimizer/IPO/CrossModuleOptimization.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,15 @@ void CrossModuleOptimization::serializeWitnessTablesInModule() {
431431
}
432432

433433
void CrossModuleOptimization::serializeVTablesInModule() {
434+
if (everything) {
435+
for (SILVTable *vt : M.getVTables()) {
436+
vt->setSerializedKind(IsSerialized);
437+
for (auto &entry : vt->getEntries()) {
438+
makeFunctionUsableFromInline(entry.getImplementation());
439+
}
440+
}
441+
return;
442+
}
434443
if (!isPackageCMOEnabled(M.getSwiftModule()))
435444
return;
436445

test/embedded/import-vtables.swift

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %{python} %utils/split_file.py -o %t %s
3+
4+
// RUN: %target-swift-frontend -emit-module -o %t/MyModule.swiftmodule %t/MyModule.swift -enable-experimental-feature Embedded -parse-as-library
5+
// RUN: %target-swift-frontend -c -I %t %t/Main.swift -enable-experimental-feature Embedded -o %t/a.o
6+
// RUN: %target-clang -x c -c %S/Inputs/print.c -o %t/print.o
7+
// RUN: %target-clang %t/a.o %t/print.o -o %t/a.out
8+
// RUN: %target-run %t/a.out | %FileCheck %s
9+
10+
// REQUIRES: swift_in_compiler
11+
// REQUIRES: executable_test
12+
// REQUIRES: OS=macosx || OS=linux-gnu
13+
// REQUIRES: swift_feature_Embedded
14+
15+
// BEGIN MyModule.swift
16+
17+
public enum MyEnum {
18+
case aCase
19+
}
20+
21+
open class BaseClass {
22+
open var type: MyEnum? { nil }
23+
}
24+
25+
public final class DerivedClass: BaseClass {
26+
public override var type: MyEnum { .aCase }
27+
28+
public override init() {
29+
}
30+
}
31+
32+
open class BaseGenericClass<T> {
33+
open var type: MyEnum? { nil }
34+
}
35+
36+
public final class DerivedGenericClass<T>: BaseGenericClass<T> {
37+
public override var type: MyEnum { .aCase }
38+
39+
public override init() {
40+
}
41+
}
42+
43+
public func createGenClass() -> BaseGenericClass<Bool> {
44+
return DerivedGenericClass<Bool>()
45+
}
46+
47+
// BEGIN Main.swift
48+
49+
import MyModule
50+
51+
let dc = DerivedClass()
52+
let dgc = DerivedGenericClass<Int>()
53+
let gc = createGenClass()
54+
print("OK!")
55+
56+
// CHECK: OK!
57+

0 commit comments

Comments
 (0)