-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Evaluate place expression in PlaceMention
#104844
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
PlaceMention
.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -331,7 +331,8 @@ pub enum StatementKind<'tcx> { | |
/// This is especially useful for `let _ = PLACE;` bindings that desugar to a single | ||
/// `PlaceMention(PLACE)`. | ||
/// | ||
/// When executed at runtime this is a nop. | ||
/// When executed at runtime, this computes the given place, but then discards | ||
/// it without doing a load. It is UB if the place is not pointing to live memory. | ||
/// | ||
/// Disallowed after drop elaboration. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that this sticks around for Miri, this comment does not seem to be true any more? |
||
PlaceMention(Box<Place<'tcx>>), | ||
|
Original file line numbe F438 r | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ fn unop_bad(string: &Option<&str>, mut num: Option<i32>) { | |
*s += 1; | ||
s | ||
} else { | ||
&mut 0 | ||
&0 | ||
}; | ||
let _ = if let Some(ref s) = num { s } else { &0 }; | ||
let _ = if let Some(mut s) = num { | ||
|
@@ -46,7 +46,7 @@ fn unop_bad(string: &Option<&str>, mut num: Option<i32>) { | |
*s += 1; | ||
s | ||
} else { | ||
&mut 0 | ||
&0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What are these clippy changes about? EDIT: Oh I see, with |
||
}; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Make sure we find these even with many checks disabled. | ||
//@compile-flags: -Zmiri-disable-alignment-check -Zmiri-disable-stacked-borrows -Zmiri-disable-validation | ||
RalfJung marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
fn main() { | ||
let p = { | ||
let b = Box::new(42); | ||
&*b as *const i32 | ||
}; | ||
let _ = unsafe { *p }; //~ ERROR: dereferenced after this allocation got freed | ||
cjgillot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
panic!("this should never print"); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error: Undefined Behavior: pointer to ALLOC was dereferenced after this allocation got freed | ||
--> $DIR/dangling_pointer_deref_underscore.rs:LL:CC | ||
| | ||
LL | let _ = unsafe { *p }; | ||
| ^^ pointer to ALLOC was dereferenced after this allocation got freed | ||
| | ||
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior | ||
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information | ||
= note: BACKTRACE: | ||
= note: inside `main` at $DIR/dangling_pointer_deref_underscore.rs:LL:CC | ||
|
||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace | ||
|
||
error: aborting due to previous error | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
error[E0716]: temporary value dropped while borrowed | ||
--> $DIR/let_underscore_temporary.rs:10:14 | ||
| | ||
LL | let _ = if let Some(s) = &mut num { | ||
| _____________- | ||
LL | | *s += 1; | ||
LL | | s | ||
LL | | } else { | ||
LL | | &mut 0 | ||
| | ^ creates a temporary value which is freed while still in use | ||
LL | | | ||
LL | | }; | ||
| | - | ||
| | | | ||
| |_____temporary value is freed at the end of this statement | ||
| borrow later used here | ||
| | ||
= note: consider using a `let` binding to create a longer lived value | ||
|
||
error[E0716]: temporary value dropped while borrowed | ||
--> $DIR/let_underscore_temporary.rs:24:14 | ||
| | ||
LL | let _ = if let Some(ref mut s) = num { | ||
| _____________- | ||
LL | | *s += 1; | ||
LL | | s | ||
LL | | } else { | ||
LL | | &mut 0 | ||
| | ^ creates a temporary value which is freed while still in use | ||
LL | | | ||
LL | | }; | ||
| | - | ||
| |_____temporary value is freed at the end of this statement | ||
| borrow later used here | ||
| | ||
= note: consider using a `let` binding to create a longer lived value | ||
|
||
error[E0716]: temporary value dropped while borrowed | ||
--> $DIR/let_underscore_temporary.rs:36:14 | ||
| | ||
LL | let _: _ = if let Some(s) = &mut num { | ||
| ________________- | ||
LL | | *s += 1; | ||
LL | | s | ||
LL | | } else { | ||
LL | | &mut 0 | ||
| | ^ creates a temporary value which is freed while still in use | ||
LL | | | ||
LL | | }; | ||
| | - | ||
| | | | ||
| |_____temporary value is freed at the end of this statement | ||
| borrow later used here | ||
| | ||
= note: consider using a `let` binding to create a longer lived value | ||
|
||
error[E0716]: temporary value dropped while borrowed | ||
--> $DIR/let_underscore_temporary.rs:50:14 | ||
| | ||
LL | let _: _ = if let Some(ref mut s) = num { | ||
| ________________- | ||
LL | | *s += 1; | ||
LL | | s | ||
LL | | } else { | ||
LL | | &mut 0 | ||
| | ^ creates a temporary value which is freed while still in use | ||
LL | | | ||
LL | | }; | ||
| | - | ||
| | | | ||
| |_____temporary value is freed at the end of this statement | ||
| borrow later used here | ||
| | ||
= note: consider using a `let` binding to create a longer lived value | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0716`. |
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.
I don't know borrowck, so someone else will have to review this part.
But doesn't this do a check that the place is actually initialized? Just to avoid UB it would be sufficient to check that the place is live, but maybe borrowck does not have such a check.
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.
Checking that the place is initialized will break a lot of code, because we allow binding moved-from places to
_
. For instance in testsrc/test/ui/binding/issue-53114-borrow-checks.rs
.Uh oh!
There was an error while loading. Please reload this page.
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.
Yes an init check is not needed. I just thought
DefUse::Use
does an init check (since usually when we use a place, we load from it, and it must be init). But it seems I am wrong about that?