Uh oh!
There was an error while loading. Please reload this page.
[validate-mir] validate that all accessed locals are initialized - #72803
[validate-mir] validate that all accessed locals are initialized#72803jonas-schievink wants to merge 1 commit into
Conversation
rust-highfive
commented
May 31, 2020
(rust_highfive has picked a reviewer for you, use r? to override) |
RalfJung
commented
May 31, 2020
The name of that pass doesn't sound like it is suited for this? We need a |
RalfJung
commented
May 31, 2020
Note that even with this check, unsafe code can still do things like let x = vec![1,2,3];let xptr = &x as*const_;move_elsewhere(x);unsafe{/* look at *xptr. */}So, "this local was moved out of" does not mean that its value is unobservable by the program! |
jonas-schievink
commented
May 31, 2020
If we wanted this to be more precise here, yes. But part of the motivation for this is to make sure that
Hmm, didn't we want to make that UB? (I don't think that impacts this check though, since the raw pointer will be its own local and accesses through that don't count as a use of |
Please define "right thing". Naively I would expect that it is correct for
Some people want to make it UB. However:
See rust-lang/unsafe-code-guidelines#188 for more discussion, and #61849 for a related proposal that doesn't make this UB but achieves something stronger through extra |
jonas-schievink
commented
May 31, 2020
Yes, that is correct, and then we couldn't use it for this validation. But since it does actually try to be a bit more precise here, it is still useful here. The docs for the pass are here, but they just refer to the rust/src/librustc_mir/dataflow/impls/init_locals.rs Lines 1 to 3 in 4b1f86a |
matthewjasper
commented
Jun 4, 2020
Does this handle something like before drop elaboration runs? |
| let ty = place.ty(&self.body.local_decls, self.tcx).ty; | ||
| if !ty.is_copy_modulo_regions(self.tcx, self.param_env, DUMMY_SP) { | ||
| if false && !ty.is_copy_modulo_regions(self.tcx, self.param_env, DUMMY_SP) { |
There was a problem hiding this comment.
Oh, this needs to be removed
jonas-schievink
commented
Jun 4, 2020
@matthewjasper yeah that looks like trouble For some reason it doesn't ICE due to this though? I think it's better to land this after the passes have been fixed anyways, that way it doesn't require changes to |
bors
commented
Jun 7, 2020
☔ The latest upstream changes (presumably #73081) made this pull request unmergeable. Please resolve the merge conflicts. |
Muirrum
commented
Jul 24, 2020
@jonas-schievink This is a triage bump. |
This uses the
MaybeInitializedLocalsdataflow analysis to validate that every use of a local happens while that local is initialized.Currently this has to ignore moves out of locals due to bugs in other passes (ie. still treat moved-out-of locals as initialized). These issues are tracked in #72797 and #72800.
cc @RalfJung