Skip to content

[embedded] Don't retain subclass vtable entries if the base method was DCE'd #72898

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/SILOptimizer/IPO/DeadFunctionElimination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,12 @@ class DeadFunctionAndGlobalElimination {
auto *fd = getBaseMethod(
cast<AbstractFunctionDecl>(entry.getMethod().getDecl()));

// In Embedded Swift, we don't expect SILFunction without definitions on
// vtable entries. Having one means the base method was DCE'd already,
// so let's avoid marking it alive in the subclass vtable either.
bool embedded = Module->getOptions().EmbeddedSwift;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eeckstein I wonder if you think this is the right approach? Alternatively, is there a way to have the subclass vtable not contain the (removed in the base class) entry in the first place?

if (embedded && !F->isDefinition()) { continue; }

if (// We also have to check the method declaration's access level.
// Needed if it's a public base method declared in another
// compilation unit (for this we have no SILFunction).
Expand Down
12 changes: 12 additions & 0 deletions test/embedded/modules-subclasses.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
// RUN: %target-clang %t/a.o %t/print.o -o %t/a.out
// RUN: %target-run %t/a.out | %FileCheck %s

// RUN: %target-swift-frontend -O -emit-module -o %t/MyModule.swiftmodule %t/MyModule.swift -enable-experimental-feature Embedded -parse-as-library
// RUN: %target-swift-frontend -O -c -I %t %t/Main.swift -enable-experimental-feature Embedded -o %t/a.o
// RUN: %target-clang -x c -c %S/Inputs/print.c -o %t/print.o
// RUN: %target-clang %t/a.o %t/print.o -o %t/a.out
// RUN: %target-run %t/a.out | %FileCheck %s

// RUN: %target-swift-frontend -Osize -emit-module -o %t/MyModule.swiftmodule %t/MyModule.swift -enable-experimental-feature Embedded -parse-as-library
// RUN: %target-swift-frontend -Osize -c -I %t %t/Main.swift -enable-experimental-feature Embedded -o %t/a.o
// RUN: %target-clang -x c -c %S/Inputs/print.c -o %t/print.o
// RUN: %target-clang %t/a.o %t/print.o -o %t/a.out
// RUN: %target-run %t/a.out | %FileCheck %s

// REQUIRES: swift_in_compiler
// REQUIRES: executable_test
// REQUIRES: OS=macosx || OS=linux-gnu
Expand Down