Skip to content

IRGen: fix failing unconditional class casts #81603

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 3 commits into from
May 19, 2025

Conversation

eeckstein
Copy link
Contributor

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 force-pushed the unconditional-class-casts branch from fbc3454 to 46314df Compare May 19, 2025 10:42
@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein eeckstein requested review from aschwaighofer, nate-chandler and mikeash and removed request for rjmccall and AnthonyLatsis May 19, 2025 10:42
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

eeckstein added 3 commits May 19, 2025 16:56
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 force-pushed the unconditional-class-casts branch from 46314df to a768037 Compare May 19, 2025 14:57
@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein eeckstein enabled auto-merge May 19, 2025 19:24
@eeckstein eeckstein merged commit 017f029 into swiftlang:main May 19, 2025
5 checks passed
@eeckstein eeckstein deleted the unconditional-class-casts branch May 20, 2025 05:13
hamishknight added a commit to hamishknight/swift that referenced this pull request May 22, 2025
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