Skip to content

[6.2] IRGen: fix failing unconditional class casts #81631

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

eeckstein
Copy link
Contributor

  • Explanation: When unconditionally casting from a base to a final derived class, e.g. base as! Derived, the program did not abort with a trap. Instead the resulting null-pointer caused a crash later in the program. This fix inserts a trap condition for the failing case of such a cast.
  • Risk: Low. It adds conditional traps for code which would have crashed anyway.
  • Testing: Tested by lit tests.
  • Issue: rdar://151462303
  • Reviewer: @mikeash, @aschwaighofer
  • Main branch PR: IRGen: fix failing unconditional class casts #81603

eeckstein added 3 commits May 20, 2025 07:39
When unconditionally casting from a base to a final derived class, e.g. `base as! Derived`, the program did not abort with a trap.
Instead the resulting null-pointer caused a crash later in the program.
This fix inserts a trap condition for the failing case of such a cast.

rdar://151462303
@eeckstein eeckstein requested a review from a team as a code owner May 20, 2025 05:42
@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein eeckstein merged commit 88a5399 into swiftlang:release/6.2 May 20, 2025
5 checks passed
@eeckstein eeckstein deleted the unconditional-class-casts-6.2 branch May 20, 2025 15:56
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.

2 participants