Skip to content

Teach exclusivity access marker verifier to handle UnsafePointer. #17935

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 2 commits into from
Jul 17, 2018
Merged

Teach exclusivity access marker verifier to handle UnsafePointer. #17935

merged 2 commits into from
Jul 17, 2018

Conversation

atrick
Copy link
Contributor

@atrick atrick commented Jul 13, 2018

My previous attempt to strengthen this verification ignored the fact that a
projection or addressor that returns UnsafePointer can have nested access after
being passed as an @inout argument. After inlining, this caused the verifier to
assert.

Instead, handle access to an UnsafePointer as a valid but unidentified access. I was trying
to avoid this because an UnsafePointer could refer to a global or class
property, which we can never consider "Unidentified". However, this is
reasonably safe because it can only result from a nested access. If a global
or class property is being addressed, it must already have its own dynamic
access within the addressor, and that access will be exposed to the
optimizer. If a non-public KeyPath is being addressed, a keypath instruction
must already exist somewhere in the module which is exposed to the optimizer.

Fixes rdar://problem/41660554 Swift CI (macOS release master, OSS): SIL verification failed: Unknown formal access pattern: storage.

@atrick
Copy link
Contributor Author

atrick commented Jul 13, 2018

@swift-ci test.

@atrick atrick requested a review from gottesmm July 13, 2018 17:50

// The compiler intrinsic _projectXXXKeyPath returns a tuple of
// UnsafePointer and Optional AnyObject. After inlining, the unsafe
// pointer may appear to orinate from anywhere, including a phi.
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: "orinate"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops thanks. Restarting the tests ;)

@atrick
Copy link
Contributor Author

atrick commented Jul 13, 2018

@swift-ci test.

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - b5fd073166f545295ae68798de9699280a0cecfd

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - b5fd073166f545295ae68798de9699280a0cecfd

Copy link
Contributor

@gottesmm gottesmm left a comment

Choose a reason for hiding this comment

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

I need to think a bit more about the semantics before giving LGTM. But a few nits and also, can you add an interpreter test? That way we know that we definitely handle the keypath version of the test in perpetuity.

assert(isa<BuiltinRawPointerType>(SEI->getType().getASTType()));
auto &C = SEI->getModule().getASTContext();
auto *decl = SEI->getStructDecl();
return (decl == C.getUnsafeMutablePointerDecl()
Copy link
Contributor

Choose a reason for hiding this comment

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

The return value here doesn't need () around it.

@@ -306,7 +306,7 @@ ExclusiveAccessTestSuite.test("SequentialKeyPathWritesDontOverlap") {

c[keyPath: getF] = 7
c[keyPath: getF] = 8 // no-trap
c[keyPath: getF] += c[keyPath: getF] + 1 // no-trap
c[keyPath: getF] += c[keyPath: getF] // no-trap
Copy link
Contributor

Choose a reason for hiding this comment

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

Question. Was this filecheck test changed for a reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cleanup in a closely related test case.

@atrick
Copy link
Contributor Author

atrick commented Jul 13, 2018

@swift-ci test.

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - ba3b6ee666eeb6b0c5c71ab302d59acd623ed31a

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - ba3b6ee666eeb6b0c5c71ab302d59acd623ed31a

@gottesmm
Copy link
Contributor

LGTM

@atrick
Copy link
Contributor Author

atrick commented Jul 13, 2018

@swift-ci smoke test and merge.

2 similar comments
@atrick
Copy link
Contributor Author

atrick commented Jul 14, 2018

@swift-ci smoke test and merge.

@atrick
Copy link
Contributor Author

atrick commented Jul 16, 2018

@swift-ci smoke test and merge.

My previous attempt to strengthen this verification ignored the fact that a
projection or addressor that returns UnsafePointer can have nested access after
being passed as an @inout argument. After inlining, this caused the verifier to
assert.

Instead, handle access to an UnsafePointer as a valid but unidentified access. I
was trying to avoid this because an UnsafePointer could refer to a global or
class property, which we can never consider "Unidentified". However, this is
reasonably safe because it can only result from a _nested_ access. If a global
or class property is being addressed, it must already have its own dynamic
access within the addressor, and that access will be exposed to the
optimizer. If a non-public KeyPath is being addressed, a keypath instruction
must already exist somewhere in the module which is exposed to the optimizer.

Fixes <rdar://problem/41660554> Swift CI (macOS release master, OSS): SIL verification failed: Unknown formal access pattern: storage.
@atrick
Copy link
Contributor Author

atrick commented Jul 17, 2018

@swift-ci smoke test and merge.

Narrow the list of address producers that verification can "peek through"
to avoid trigger an assertion in the previous commit with
-enable-verify-exclusivity.
@atrick
Copy link
Contributor Author

atrick commented Jul 17, 2018

@swift-ci smoke test.

@atrick atrick merged commit e911e1f into swiftlang:master Jul 17, 2018
@atrick atrick deleted the fix-keypath-exclusivity-verify branch July 18, 2018 22:39
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.

4 participants