Skip to content

[5.1] SILOptimier: Fix a miscompile in COWArrayOpt. #23431

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 1 commit into from
Mar 20, 2019

Conversation

eeckstein
Copy link
Contributor

If a make_mutable operation is done conditionally in a loop, the hoisting of this operation can cause an over-release of the array buffer in some cases.

rdar://problem/48906146

If a make_mutable operation is done conditionally in a loop, the hoisting of this operation can cause an over-release of the array buffer in some cases.

rdar://problem/48906146
@eeckstein
Copy link
Contributor Author

@swift-ci smoke test and merge

@eeckstein
Copy link
Contributor Author

@swift-ci test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - a71d182

// conditionally (i.e. doesn't dominate all exit blocks).
// The test SILOptimizer/cowarray_opt.sil: dont_hoist_if_executed_conditionally
// shows the problem.
if (hasLoopOnlyDestructorSafeArrayOperations() && dominatesExits) {
// Done. We can hoist the make_mutable.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see an obvious connection between the comment and the test case. Here's my guess at how it works... For potentially aliased arrays, I think it's this pass' job to determine that a potential alias can't be accessed on any path from the loop header that does not pass through the original make_mutable. I guess we already do that within the loop but never checked outside the loop?

That isn't clear from the comment. Shouldn't it say something like:

The hoisted make_mutable releases the original array storage. If an
alias of that storage is accessed on any path reachable from the
header that doesn't already pass through make_mutable, then hoisting
is illegal. hasLoopOnlyDestructorSafeArrayOperations checks that the
array storage is not accessed within the loop. However, the array may
also be accessed after exiting the loop. Rather than analyzing code
outside the loop, simply check that the original make_mutable
dominates all exits.

I'm not sure if the above is actually true but at least it makes sense to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's probably a better way to describe it.

@eeckstein
Copy link
Contributor Author

@swift-ci test linux

@eeckstein eeckstein merged commit a9ed8bb into swiftlang:swift-5.1-branch Mar 20, 2019
@eeckstein eeckstein deleted the fix-cowarrayopt-5.1 branch March 20, 2019 20:22
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