Skip to content

[4.1] IRGen: Fix witness-table accessors for conditional conformances #15454

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

Conversation

aschwaighofer
Copy link
Contributor

Explanation: After adding conditional conformances witness table
accessors are no longer readnone because the witnesses are passed as an
in memory argument. In optimized mode LLVM will optimize away the store
of the witnesses because it believes the accessor function is readnone
leading to crashes

Scope: Introduced with conditional conformances, potentially affects any project
that emit witness-table accessors on based types with conditional
conformances

Risk: Very low since the fix is to not emit LLVM's readnone attribute
(which should do no harm)

Testing: The project on which this was reported was tested and a CI test
added

SR-7228
rdar://38624842

Explanation: After adding conditional conformances witness table
accessors are no longer readnone because the witnesses are passed as an
in memory argument. In optimized mode LLVM will optimize away the store
of the witnesses because it believes the accessor function is readnone
leading to crashes

Scope: Introduced with conditional conformances, potentially affects any project
that emit witness-table accessors on based types with conditional
conformances

Risk: Very low since the fix is to not emit LLVM's readnone attribute
(which should do no harm)

Testing: The project on which this was reported was tested and a CI test
added

SR-7228
rdar://38624842
@aschwaighofer
Copy link
Contributor Author

@swift-ci Please test

@aschwaighofer aschwaighofer requested a review from huonw March 23, 2018 15:24
@aschwaighofer
Copy link
Contributor Author

@huonw Can you review this change?

@aschwaighofer
Copy link
Contributor Author

@swift-ci please nominate

@aschwaighofer
Copy link
Contributor Author

This is a cherry-pick of #15397

@aschwaighofer
Copy link
Contributor Author

@shahmishal In case this is interesting to you and not just temporary fallout: https://ci.swift.org/job/swift-PR-osx/3839/
10:56:36 FATAL: command execution failed
10:56:36 java.io.IOException

Restarting the test.

@aschwaighofer
Copy link
Contributor Author

@swift-ci Please test

Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for catching this.

I fixed a similar problem not too long ago with a rogue "readnone" that caused obscure runtime failures. Should we perform a holistic audit of the use of these attributes in IRGen?

@aschwaighofer
Copy link
Contributor Author

I went over all instances of the following in IRGen on master:

ReadNone
ReadOnly
setOnlyReadsMemory
setDoesNotAccessMemory

@aschwaighofer aschwaighofer merged commit 364c296 into swiftlang:swift-4.1-branch Mar 23, 2018
@huonw
Copy link
Contributor

huonw commented Mar 24, 2018

This is unfortunate. Thank you!

I wonder if it'd be worth having a verifier that validates that that there's no static readnone calls to non-readnone functions to protect against bugs like this in future, since it seems like a trivial thing to check and very problematic in non-obvious ways when wrong.

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