-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
[validate-mir] validate that all accessed locals are initialized #72803
[validate-mir] validate that all accessed locals are initialized #72803
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
The name of that pass doesn't sound like it is suited for this? We need a |
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! |
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 |
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
|
Does this handle something like
before drop elaboration runs? |
@@ -46,7 +66,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { | |||
if let Operand::Copy(place) = operand { | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, this needs to be removed
@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 |
☔ The latest upstream changes (presumably #73081) made this pull request unmergeable. Please resolve the merge conflicts. |
@jonas-schievink This is a triage bump. |
This uses the
MaybeInitializedLocals
dataflow 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