Skip to content

[5.10] WalkUtils: handle unsafe_ref_cast which casts between AnyObject and a class #75445

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

Closed
wants to merge 1 commit into from

Conversation

eeckstein
Copy link
Contributor

  • Explanation: Fixes a mis-compile caused by a bug in escape analysis. Certain casts in the stdlib between AnyObject and a class is done with an unsafe_ref_cast instruction instead of init_existential_ref and open_existential_ref. This happens for example in unsafeDownCast. This is not handled correctly in escape analysis. Therefore optimizations, which use escape analysis, like redundant-load-elimination, can mis-compile such patterns.
  • Scope: Can affect code which uses unsafeDownCast or similar unsafe cast utilities from the stdlib.
  • Risk: Low. The change adds a bail-out condition in escape analysis for exactly this case.
  • Testing: Tested by test cases.
  • Issue: rdar://132364917
  • Reviewer: @atrick (to-do)
  • Main branch PR: WalkUtils: handle unsafe_ref_cast which casts between AnyObject and a class #75434

… a class

We need to ignore such casts because otherwise the constructed walking path wouldn't contain the right `existential` field kind.
Fixes a miscompile caused by redundant load elimination.

rdar://132364917

# Conflicts:
#	SwiftCompilerSources/Sources/Optimizer/Utilities/WalkUtils.swift
#	include/swift/SIL/SILBridging.h
#	include/swift/SIL/SILBridgingImpl.h
#	test/SILOptimizer/addr_escape_info.sil
#	test/SILOptimizer/redundant_load_elim.sil
@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein eeckstein requested review from atrick and shahmishal July 24, 2024 18:21
@eeckstein
Copy link
Contributor Author

@swift-ci test windows

@eeckstein eeckstein closed this Feb 10, 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.

2 participants