Skip to content

[IRGen] Fix witness table miscompilation. #60529

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 5 commits into from
Aug 23, 2022

Conversation

al45tair
Copy link
Contributor

If a foreign type conforms to a protocol, and that conformance is not resilient, we were emitting an instantantiation function but it would never be called because we weren't emitting the GenericWitnessTable that would have contained a reference to it.

This was happening because of a missing isSynthesizedNonUnique() call in isDependentConformance().

rdar://97290618

@al45tair
Copy link
Contributor Author

@swift-ci Please smoke test

@al45tair
Copy link
Contributor Author

Hmmm. That exploded unexpectedly. I'll keep digging then.

@aschwaighofer
Copy link
Contributor

Is it possible to add a test case?

@al45tair
Copy link
Contributor Author

Is it possible to add a test case?

Should be, yes.

@al45tair
Copy link
Contributor Author

@swift-ci Please smoke test

Copy link
Contributor

@rjmccall rjmccall left a comment

Choose a reason for hiding this comment

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

LGTM except that it's missing a test case.

@al45tair
Copy link
Contributor Author

Having looked at this a bit further, I don't think it's feasible to write a test case that will work on macOS (this only affects synthesized conformances, which means the protocol in question needs to be in the Swift standard library, but on macOS that's dynamically linked and always resilient; building a test case there would require a fairly heroic effort), but it's probably possible on Linux. Trying to get a Linux build up so I can test it.

@al45tair
Copy link
Contributor Author

Having looked at this a bit further, I don't think it's feasible to write a test case that will work on macOS

It turns out that it was feasible. Just somewhat tricky to get right (the compiler doesn't give very helpful error messages when bits of the Swift module are missing; it often just crashes somewhere instead).

@al45tair
Copy link
Contributor Author

@swift-ci Please smoke test

Copy link
Contributor

@aschwaighofer aschwaighofer left a comment

Choose a reason for hiding this comment

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

lgtm

@al45tair
Copy link
Contributor Author

Failed on Windows and Linux, probably because of the section name. Looking at that now.

@al45tair
Copy link
Contributor Author

@swift-ci Please smoke test

If a foreign type conforms to a protocol, and that conformance is not
resilient, we were emitting an instantantiation function but it would
never be called because we weren't emitting the `GenericWitnessTable`
that would have contained a reference to it.

This was happening because of a missing `isSynthesizedNonUnique()` call
in `isDependentConformance()`.

rdar://97290618
isDependentConformance() should always check for synthesized conformances,
so do that further up the function.

Also add a test.

rdar://97290618
Changed the test case to pattern match various parts to make it work
on 32-bit.

rdar://97290618
Windows adds a `comdat` flag.

rdar://97290618
Linux uses different section names.

rdar://97690618
@al45tair
Copy link
Contributor Author

@swift-ci Please smoke test

Copy link
Contributor

@rjmccall rjmccall left a comment

Choose a reason for hiding this comment

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

LGTM

@al45tair al45tair merged commit b9971cc into swiftlang:main Aug 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants