Skip to content

Commit 28213cd

Browse files
authored
Merge pull request #72917 from kubamracek/cp/6.0/embedded-dce-superclass-vtable-entries
[6.0 cherry-pick][embedded] Don't retain subclass vtable entries if the base method was DCE'd
2 parents 5f78ea1 + e80b8e5 commit 28213cd

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/SILOptimizer/IPO/DeadFunctionElimination.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,12 @@ class DeadFunctionAndGlobalElimination {
556556
auto *fd = getBaseMethod(
557557
cast<AbstractFunctionDecl>(entry.getMethod().getDecl()));
558558

559+
// In Embedded Swift, we don't expect SILFunction without definitions on
560+
// vtable entries. Having one means the base method was DCE'd already,
561+
// so let's avoid marking it alive in the subclass vtable either.
562+
bool embedded = Module->getOptions().EmbeddedSwift;
563+
if (embedded && !F->isDefinition()) { continue; }
564+
559565
if (// We also have to check the method declaration's access level.
560566
// Needed if it's a public base method declared in another
561567
// compilation unit (for this we have no SILFunction).

test/embedded/modules-subclasses.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@
77
// RUN: %target-clang %t/a.o %t/print.o -o %t/a.out
88
// RUN: %target-run %t/a.out | %FileCheck %s
99

10+
// RUN: %target-swift-frontend -O -emit-module -o %t/MyModule.swiftmodule %t/MyModule.swift -enable-experimental-feature Embedded -parse-as-library
11+
// RUN: %target-swift-frontend -O -c -I %t %t/Main.swift -enable-experimental-feature Embedded -o %t/a.o
12+
// RUN: %target-clang -x c -c %S/Inputs/print.c -o %t/print.o
13+
// RUN: %target-clang %t/a.o %t/print.o -o %t/a.out
14+
// RUN: %target-run %t/a.out | %FileCheck %s
15+
16+
// RUN: %target-swift-frontend -Osize -emit-module -o %t/MyModule.swiftmodule %t/MyModule.swift -enable-experimental-feature Embedded -parse-as-library
17+
// RUN: %target-swift-frontend -Osize -c -I %t %t/Main.swift -enable-experimental-feature Embedded -o %t/a.o
18+
// RUN: %target-clang -x c -c %S/Inputs/print.c -o %t/print.o
19+
// RUN: %target-clang %t/a.o %t/print.o -o %t/a.out
20+
// RUN: %target-run %t/a.out | %FileCheck %s
21+
1022
// REQUIRES: swift_in_compiler
1123
// REQUIRES: executable_test
1224
// REQUIRES: OS=macosx || OS=linux-gnu

0 commit comments

Comments
 (0)