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

Conversation

kubamracek
Copy link
Contributor

The reproducer for this problem is a -O/-Osize version of a testcase we already have, test/embedded/modules-subclasses.swift. What happens is that under -O/-Osize, the module that defines the base class has an unused internal method on the class, that method is proven by DeadFunctionElimination to be unused, and is removed from the base vtable. The client module then defines a subclass, and the subclass vtable references the (removed) base class method.

This PR simply allows DeadFunctionElimination on the client module to remove the entry from the subclass as well.

Fixes #72890.

rdar://126044717

@kubamracek kubamracek added the embedded Embedded Swift label Apr 7, 2024
// 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?

Copy link
Contributor

@eeckstein eeckstein left a comment

Choose a reason for hiding this comment

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

lgtm!

@kubamracek
Copy link
Contributor Author

@swift-ci please test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
embedded Embedded Swift
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Undefined reference when subclassing class with internal/private methods
2 participants