Skip to content

[6.0] SILGen: Correct handling of subscripts with addressors. #73411

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

jckarter
Copy link
Contributor

@jckarter jckarter commented May 3, 2024

Explanation: Fixes a spurious move-only checking error when using UnsafeBufferPointer's subscript as a borrowing parameter of noncopyable type.
Scope: Bug fix.
Issue: rdar://127335590.
Original PR: #73410
Risk: Medium-low. The refactoring has a chance of affecting existing code using noncopyable types.
Testing: Swift CI, test case from bug report
Reviewer: @kavon

Remove improper special-case handling of subscripts in `findStorageReferenceExprForMoveOnly`.
The correct thing to do for any storage decl ref of noncopyable type is to emit it as a borrow
if it's implemented using storage, a read accessor, or an addressor. Fixes rdar://127335590.
@jckarter jckarter requested a review from a team as a code owner May 3, 2024 02:38
@jckarter
Copy link
Contributor Author

jckarter commented May 3, 2024

@swift-ci Please test

Comment on lines -3361 to +3347
storage = dyn_cast<VarDecl>(mre->getDecl().getDecl());
storage = dyn_cast<AbstractStorageDecl>(mre->getDecl().getDecl());
type = mre->getType();
} else if (auto se = dyn_cast<SubscriptExpr>(result.getStorageRef())) {
storage = dyn_cast<AbstractStorageDecl>(se->getDecl().getDecl());
type = se->getType();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice fix!

@jckarter jckarter merged commit 21b30a7 into swiftlang:release/6.0 May 13, 2024
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