Skip to content

Conversation

eeckstein
Copy link
Contributor

@eeckstein eeckstein commented Aug 29, 2025

  • TempLValueElimination: don't propagate alloc_stack which have access scopes

If exclusivity is checked for the alloc_stack we must not replace it with the copy-destination.
If the copy-destination is also in an access-scope this would result in an exclusivity violation which was not there before.

Fixes a miscompile which results in a wrong exclusivity violation error at runtime.
#83924
rdar://159220436

  • RawSILInstLowering: Don't inserted an access scope for assign_or_init if there is already one.

This avoids inserting a dynamic access check when the parent is static (and therefore can be statically enforced).

  • AllocBoxToStack: convert access checks from "dynamic" to "static"

Once we have promoted the box to stack, access violations can be detected statically by the DiagnoseStaticExclusivity pass (which runs after MandatoryAllocBoxToStack).
Therefore we can convert dynamic accesses to static accesses.

rdar://157458037

  • Move DiagnoseStaticExclusivity after MandatoryAllocBoxToStack

This is needed because MandatoryAllocBoxToStack can convert dynamic accesses to static accesses.
Also, it improves diagnostics for closure captures.

@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein eeckstein requested a review from xedin August 29, 2025 12:00
@eeckstein
Copy link
Contributor Author

@swift-ci apple silicon benchmark

Copy link
Contributor

@nate-chandler nate-chandler 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
Copy link
Contributor Author

@swift-ci smoke test windows

This is needed because MandatoryAllocBoxToStack can convert dynamic accesses to static accesses.
Also, it improves diagnostics for closure captures.
… if there is already one.

This avoids inserting a dynamic access check when the parent is static (and therefore can be statically enforced).
…scopes

If exclusivity is checked for the alloc_stack we must not replace it with the copy-destination.
If the copy-destination is also in an access-scope this would result in an exclusivity violation which was not there before.

Fixes a miscompile which results in a wrong exclusivity violation error at runtime.
swiftlang#83924
rdar://159220436
Once we have promoted the box to stack, access violations can be detected statically by the DiagnoseStaticExclusivity pass (which runs after MandatoryAllocBoxToStack).
Therefore we can convert dynamic accesses to static accesses.

rdar://157458037
@eeckstein eeckstein force-pushed the access-enforcement-improvements branch from 610ba94 to c790052 Compare August 30, 2025 05:29
@eeckstein
Copy link
Contributor Author

@swift-ci smoke test

@eeckstein
Copy link
Contributor Author

@swift-ci smoke test macos

@eeckstein eeckstein merged commit c2cd172 into swiftlang:main Aug 31, 2025
3 checks passed
@eeckstein eeckstein deleted the access-enforcement-improvements branch September 1, 2025 05:03
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