Skip to content

[5.3] [semantic-arc-opts] Use all consuming uses instead of just destroying uses when validating if a LiveRange is alive in a scope. #32130

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
Jun 10, 2020

Conversation

gottesmm
Copy link
Contributor

@gottesmm gottesmm commented Jun 2, 2020

Just cherry-picking this fix.

rdar://63188362


Explanation: SemanticARCOpts is converting a legally leakable load [copy] from an access scope to a load_borrow in an harmless, incorrect way. Specifically to transform a load [copy] from an access_scope to a load_borrow, we need to validate that all uses of a load [copy] are within the access scope since load_borrows can only be used while the access_scope is valid. In the algorithm as written, we validate only that the destroy_value of the load [copy] are within that scope since all non-destroy uses will be earlier than such destroy_value. This is generally correct, except if our load [copy] is post-dominated by an unreachable. In such cases we may eliminate all destroy_value on the load [copy] since the program is going to end and we are going to leak the object. This can then cause us to ignore any non-destroy uses of the load [copy] outside of the access scope that would disqualify the load [copy] from being converted to a load_borrow. This change fixes the problem conservatively by just validating that /all/ uses of a load [copy] (rather than just destroy_value uses) are strictly within the access scope.
Scope: Fixes a miscompile. In terms of how likely this is in practice, I think it is not likely. That is because the optimizer is pretty aggressive about leaking objects on program exit. So given that we need to be post-dominated by unreachables, the base object is likely to be leaked rather than destroyed.
SR Issue: rdar://63188362
Risk: Low. I am only making the algorithm more conservative by adding all uses to a check instead of just the destroy_values.
Testing: Added a test case. Just run the compiler test suite.
Reviewer: @atrick

… uses when validating if a LiveRange is alive in a scope.

The reason why this is important is that if our destroy_value is elided due to
the destroy_value being in a dead end block, we can promote a load [copy] to a
load_borrow even if the load [copy] has a forwarding consuming use outside of a
begin_access region.

I changed every place in SemanticARCOpts that did this sort of thing to use this
pattern instead of just destroys so that no one cargo cults the original pattern
by mistake.

<rdar://problem/61774105>

(cherry picked from commit ba1ac78)

Cherry-pick radar: rdar://63188362
@gottesmm gottesmm requested a review from atrick June 2, 2020 03:07
@gottesmm gottesmm changed the base branch from master to release/5.3 June 2, 2020 03:08
@gottesmm
Copy link
Contributor Author

gottesmm commented Jun 2, 2020

@swift-ci test

@compnerd compnerd added the r5.3 label Jun 2, 2020
Copy link
Contributor

@atrick atrick left a comment

Choose a reason for hiding this comment

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

LGTM for 5.3

@gottesmm gottesmm marked this pull request as ready for review June 9, 2020 19:42
@gottesmm gottesmm requested a review from a team as a code owner June 9, 2020 19:42
@gottesmm
Copy link
Contributor Author

gottesmm commented Jun 9, 2020

@swift-ci test

@gottesmm
Copy link
Contributor Author

gottesmm commented Jun 9, 2020

Just redoing the test since it has been a minute since I put this up.

@swift-ci
Copy link
Contributor

swift-ci commented Jun 9, 2020

Build failed
Swift Test Linux Platform
Git Sha - 2f10202

@swift-ci
Copy link
Contributor

swift-ci commented Jun 9, 2020

Build failed
Swift Test OS X Platform
Git Sha - 2f10202

@gottesmm
Copy link
Contributor Author

gottesmm commented Jun 9, 2020

The OS X failure was a Jenkins failure. And the Linux I think was one of those non-deterministic swiftpm ones:

Test Case 'WorkspaceTests.testTransitiveDependencySwitchWithSameIdentity' started at 2020-06-09 21:42:23.041
Exited with signal code 11
env SWIFTCI_USE_LOCAL_DEPS=1 SWIFTPM_MACOS_DEPLOYMENT_TARGET=10.15 LD_LIBRARY_PATH=/home/buildnode/jenkins/workspace/swift-PR-Linux@2/branch-release/5.3/buildbot_linux/swiftpm-linux-x86_64/x86_64-unknown-linux-gnu/bootstrap/lib:/home/buildnode/jenkins/workspace/swift-PR-Linux@2/branch-release/5.3/buildbot_linux/swiftpm-linux-x86_64/x86_64-unknown-linux-gnu/tsc/lib:/home/buildnode/jenkins/workspace/swift-PR-Linux@2/branch-release/5.3/buildbot_linux/llbuild-linux-x86_64/lib /home/buildnode/jenkins/workspace/swift-PR-Linux@2/branch-release/5.3/buildbot_linux/swiftpm-linux-x86_64/x86_64-unknown-linux-gnu/release/swift-test --enable-test-discovery --parallel --build-path /home/buildnode/jenkins/workspace/swift-PR-Linux@2/branch-release/5.3/buildbot_linux/swiftpm-linux-x86_64 --configuration release -Xlinker -rpath -Xlinker $ORIGIN/../lib/swift/linux
env SWIFTCI_USE_LOCAL_DEPS=1 SWIFTPM_MACOS_DEPLOYMENT_TARGET=10.15 LD_LIBRARY_PATH=/home/buildnode/jenkins/workspace/swift-PR-Linux@2/branch-release/5.3/buildbot_linux/swiftpm-linux-x86_64/x86_64-unknown-linux-gnu/bootstrap/lib:/home/buildnode/jenkins/workspace/swift-PR-Linux@2/branch-release/5.3/buildbot_linux/swiftpm-linux-x86_64/x86_64-unknown-linux-gnu/tsc/lib:/home/buildnode/jenkins/workspace/swift-PR-Linux@2/branch-release/5.3/buildbot_linux/llbuild-linux-x86_64/lib /home/buildnode/jenkins/workspace/swift-PR-Linux@2/branch-release/5.3/buildbot_linux/swiftpm-linux-x86_64/x86_64-unknown-linux-gnu/release/swift-test --enable-test-discovery --parallel --build-path /home/buildnode/jenkins/workspace/swift-PR-Linux@2/branch-release/5.3/buildbot_linux/swiftpm-linux-x86_64 --configuration release -Xlinker -rpath -Xlinker $ORIGIN/../lib/swift/linux
--- bootstrap: error: Command '['env', 'SWIFTCI_USE_LOCAL_DEPS=1', 'SWIFTPM_MACOS_DEPLOYMENT_TARGET=10.15', u'LD_LIBRARY_PATH=/home/buildnode/jenkins/workspace/swift-PR-Linux@2/branch-release/5.3/buildbot_linux/swiftpm-linux-x86_64/x86_64-unknown-linux-gnu/bootstrap/lib:/home/buildnode/jenkins/workspace/swift-PR-Linux@2/branch-release/5.3/buildbot_linux/swiftpm-linux-x86_64/x86_64-unknown-linux-gnu/tsc/lib:/home/buildnode/jenkins/workspace/swift-PR-Linux@2/branch-release/5.3/buildbot_linux/llbuild-linux-x86_64/lib', u'/home/buildnode/jenkins/workspace/swift-PR-Linux@2/branch-release/5.3/buildbot_linux/swiftpm-linux-x86_64/x86_64-unknown-linux-gnu/release/swift-test', '--enable-test-discovery', '--parallel', '--build-path', '/home/buildnode/jenkins/workspace/swift-PR-Linux@2/branch-release/5.3/buildbot_linux/swiftpm-linux-x86_64', '--configuration', 'release', '-Xlinker', '-rpath', '-Xlinker', u'$ORIGIN/../lib/swift/linux']' returned non-zero exit status 1

Going to retest

@gottesmm
Copy link
Contributor Author

gottesmm commented Jun 9, 2020

@swift-ci test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 2f10202

@gottesmm
Copy link
Contributor Author

Going to wait for things to calm down on the CI

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 2f10202

@gottesmm
Copy link
Contributor Author

@swift-ci test

1 similar comment
@gottesmm
Copy link
Contributor Author

@swift-ci test

@gottesmm
Copy link
Contributor Author

@swift-ci nominate

@tkremenek tkremenek merged commit 24370b7 into swiftlang:release/5.3 Jun 10, 2020
@gottesmm gottesmm deleted the release/5.3-rdar63188362 branch June 10, 2020 19:06
@AnthonyLatsis AnthonyLatsis added swift 5.3 🍒 release cherry pick Flag: Release branch cherry picks labels Jan 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 release cherry pick Flag: Release branch cherry picks swift 5.3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants