-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Under feature(capture_disjoint_fields), unsafe-checking has false positives under unsafe blocks #85561
Comments
(and thus exposed underlying issue rust-lang#85561).
searched nightlies: from nightly-2021-03-04 to nightly-2021-05-21 bisected with cargo-bisect-rustc v0.6.0Host triple: x86_64-unknown-linux-gnu cargo bisect-rustc --access github --preserve |
cc @roxelo |
So the solution to bug I think this would not cause problems because:
|
Before we jump into the approach outlined by @arora-aman : we are expecting to move the unsafe-checking from MIR to THIR, according to rust-lang/compiler-team#402 . Won't that shift also resolve this issue? |
I'm not aware of that, I'll read through that. But I don't think we should be adding fake reads of raw pointers dereference anyway. As I understand it, the fake reads are less precise closure captures to facilitate pattern matching (in both let and match) and we shouldn't be capturing raw pointer dereference. |
It doesn't seem like rust-lang/compiler-team#402 is going to be done any time soon (and I am not entirely sure if that will fix the bug or not), wouldn't it be better for the time being to attempt @arora-aman's suggestion? It should be a quick fix |
Since yesterday (#85555), dereferences of raw pointers is implemented in the THIR unsafety checker (gated under
I'm not sure how much time it will take to make the THIR unsafety checker the default once it is fully implemented, but the implementation itself is going rather fast (see rust-lang/project-thir-unsafeck#7). |
@arora-aman @roxelo can you spell out a bit more what is happening? What fake reads do we introduce? |
So when we have something like let raw_ptr: *i32;
let c = || {
let x = *raw_ptr;
....
}; The MIR that will be generated will be something like
The reason we have the fake read is to test that the right hand side of the let (and in other examples scrutinee of a match) have been initialized. Since the RHS of let/match scrutinee can be less precise than what a closure captures, we do a FakeRead them outside the closure so as to not capture them for the initialization test. This means it's fine to do FakeRead an even less precise place, eg. in case of raw pointers don't FakeRead the deref projection. So my proposal is to apply all the restrictions on closure captures around unsafe code (deref of raw ptr, reference into a repr packed struct) to the Fake Reads that are introduced for let/match on upvars in closure. Updated MIR would then be:
|
OK, I agree that adding the |
…disjoint-fields-gate, r=nikomatsakis readd capture disjoint fields gate This readds a feature gate guard that was added in PR rust-lang#83521. (Basically, there were unintended consequences to the code exposed by removing the feature gate guard.) The root bug still remains to be resolved, as discussed in issue rust-lang#85561. This is just a band-aid suitable for a beta backport. Cc issue rust-lang#85435 Note that the latter issue is unfixed until we backport this (or another fix) to 1.53 beta
…disjoint-fields-gate, r=nikomatsakis readd capture disjoint fields gate This readds a feature gate guard that was added in PR rust-lang#83521. (Basically, there were unintended consequences to the code exposed by removing the feature gate guard.) The root bug still remains to be resolved, as discussed in issue rust-lang#85561. This is just a band-aid suitable for a beta backport. Cc issue rust-lang#85435 Note that the latter issue is unfixed until we backport this (or another fix) to 1.53 beta
…disjoint-fields-gate, r=nikomatsakis readd capture disjoint fields gate This readds a feature gate guard that was added in PR rust-lang#83521. (Basically, there were unintended consequences to the code exposed by removing the feature gate guard.) The root bug still remains to be resolved, as discussed in issue rust-lang#85561. This is just a band-aid suitable for a beta backport. Cc issue rust-lang#85435 Note that the latter issue is unfixed until we backport this (or another fix) to 1.53 beta
(and thus exposed underlying issue rust-lang#85561).
…nikomatsakis Fix issue 85435 by restricting Fake Read precision This PR fixes the root bug of issue rust-lang#85435 by restricting Fake Read precision in closures and removing the feature gate introduced in PR rust-lang#85564. More info [here](rust-lang#85561 (comment)) and [here](rust-lang#85561 (comment)). Closes rust-lang#85561 r? `@nikomatsakis`
Spawned off of issue #85435
I tried this code on nightly:
I expected to see this happen: Code accepted by compiler
Instead, this happened:
Note: This has same root cause as #85435. But, we're going to address #85435 with a targeted short-term fix (namely PR #85564), so that it won't hit stable. So I'm filing this bug to track fixing the root cause.
The text was updated successfully, but these errors were encountered: