Skip to content

[6.0] IRGen: don't stack promote classes for which the layout has not a fixed size #74982

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 1 commit into from
Jul 8, 2024

Conversation

eeckstein
Copy link
Contributor

@eeckstein eeckstein commented Jul 5, 2024

  • Explanation: Fixes a mis-compile caused by stack promotion of classes. The reserved stack space was wrong for classes which are imported from another module and contain implementation-only C-imported stored properties. Those properties don't show up in the class layout and make the class not "fixed size". For other cases of not fixed-size classes (e.g. classes containing resilient properties) this was already checked with ClassLayout::isFixedLayout. But for this specific case a check with ClassLayout::isFixedSize is required.
  • Scope: Affects code using classes as described above
  • Risk: Low. The changes adds a simple bail-out condition for stack promotion
  • Testing: Tested by a test case
  • Issue: rdar://131067105
  • Reviewer: @slavapestov
  • Main branch PR: IRGen: don't stack promote classes for which the layout has not a fixed size #74969

…ed size

In most cases this was already checked with `ClassLayout::isFixedLayout`. But for classes which are imported from another module and contain implementation-only C-imported stored properties, those properties don't show up in the class layout. Stack promoting such classes will reserve too less space on the stack which leads to all kind of memory corruption problems. The fix is to also check `ClassLayout::isFixedSize`, which returns false for such classes.

Fixes a miscompile
rdar://131067105
@eeckstein eeckstein requested a review from a team as a code owner July 5, 2024 07:35
@eeckstein eeckstein requested a review from aschwaighofer July 5, 2024 07:35
@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein eeckstein merged commit 4b9e512 into swiftlang:release/6.0 Jul 8, 2024
5 checks passed
@eeckstein eeckstein deleted the fix-stack-promotion-6.0 branch July 8, 2024 06:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants