-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Retag as FnEntry on drop_in_place
#103957
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/tools/miri/tests/fail/stacked_borrows/drop_in_place_protector.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//! Test that drop_in_place retags the entire place, | ||
//! invalidating all aliases to it. | ||
|
||
// A zero-sized drop type -- the retagging of `fn drop` itself won't | ||
// do anything (since it is zero-sized); we are entirely relying on the retagging | ||
// in `drop_in_place` here. | ||
#[repr(transparent)] | ||
struct HasDrop; | ||
impl Drop for HasDrop { | ||
fn drop(&mut self) { | ||
unsafe { | ||
let _val = *P; | ||
//~^ ERROR: /not granting access .* because that would remove .* which is strongly protected/ | ||
} | ||
} | ||
} | ||
|
||
static mut P: *mut u8 = core::ptr::null_mut(); | ||
|
||
fn main() { | ||
unsafe { | ||
let mut x = (HasDrop, 0u8); | ||
let x = core::ptr::addr_of_mut!(x); | ||
P = x.cast(); | ||
core::ptr::drop_in_place(x); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/tools/miri/tests/fail/stacked_borrows/drop_in_place_protector.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
error: Undefined Behavior: not granting access to tag <TAG> because that would remove [Unique for <TAG>] which is strongly protected because it is an argument of call ID | ||
--> $DIR/drop_in_place_protector.rs:LL:CC | ||
| | ||
LL | let _val = *P; | ||
| ^^ not granting access to tag <TAG> because that would remove [Unique for <TAG>] which is strongly protected because it is an argument of call ID | ||
| | ||
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental | ||
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information | ||
help: <TAG> was created by a SharedReadWrite retag at offsets [0x0..0x1] | ||
--> $DIR/drop_in_place_protector.rs:LL:CC | ||
| | ||
LL | let x = core::ptr::addr_of_mut!(x); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
help: <TAG> is this argument | ||
--> $DIR/drop_in_place_protector.rs:LL:CC | ||
| | ||
LL | core::ptr::drop_in_place(x); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
= note: BACKTRACE: | ||
= note: inside `<HasDrop as std::ops::Drop>::drop` at $DIR/drop_in_place_protector.rs:LL:CC | ||
= note: inside `std::ptr::drop_in_place::<HasDrop> - shim(Some(HasDrop))` at RUSTLIB/core/src/ptr/mod.rs:LL:CC | ||
= note: inside `std::ptr::drop_in_place::<(HasDrop, u8)> - shim(Some((HasDrop, u8)))` at RUSTLIB/core/src/ptr/mod.rs:LL:CC | ||
note: inside `main` | ||
--> $DIR/drop_in_place_protector.rs:LL:CC | ||
| | ||
LL | core::ptr::drop_in_place(x); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
= note: this error originates in the macro `core::ptr::addr_of_mut` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace | ||
|
||
error: aborting due to previous error | ||
|
12 changes: 12 additions & 0 deletions
12
src/tools/miri/tests/fail/stacked_borrows/drop_in_place_retag.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
//! Test that drop_in_place mutably retags the entire place, even for a type that does not need | ||
//! dropping, ensuring among other things that it is writeable | ||
|
||
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. Might be worth indicating in the test name and/or comment that this is specifically about |
||
//@error-pattern: /retag .* for Unique permission .* only grants SharedReadOnly permission/ | ||
|
||
fn main() { | ||
unsafe { | ||
let x = 0u8; | ||
let x = core::ptr::addr_of!(x); | ||
core::ptr::drop_in_place(x.cast_mut()); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/tools/miri/tests/fail/stacked_borrows/drop_in_place_retag.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
error: Undefined Behavior: trying to retag from <TAG> for Unique permission at ALLOC[0x0], but that tag only grants SharedReadOnly permission for this location | ||
--> RUSTLIB/core/src/ptr/mod.rs:LL:CC | ||
| | ||
LL | pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| trying to retag from <TAG> for Unique permission at ALLOC[0x0], but that tag only grants SharedReadOnly permission for this location | ||
| this error occurs as part of retag at ALLOC[0x0..0x1] | ||
| | ||
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental | ||
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information | ||
help: <TAG> was created by a SharedReadOnly retag at offsets [0x0..0x1] | ||
--> $DIR/drop_in_place_retag.rs:LL:CC | ||
| | ||
LL | let x = core::ptr::addr_of!(x); | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
= note: BACKTRACE: | ||
= note: inside `std::ptr::drop_in_place::<u8> - shim(None)` at RUSTLIB/core/src/ptr/mod.rs:LL:CC | ||
note: inside `main` | ||
--> $DIR/drop_in_place_retag.rs:LL:CC | ||
| | ||
LL | core::ptr::drop_in_place(x.cast_mut()); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
= note: this error originates in the macro `core::ptr::addr_of` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace | ||
|
||
error: aborting due to previous error | ||
|
25 changes: 25 additions & 0 deletions
25
src/tools/miri/tests/fail/unaligned_pointers/drop_in_place.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#[repr(transparent)] | ||
struct HasDrop(u8); | ||
|
||
impl Drop for HasDrop { | ||
fn drop(&mut self) {} | ||
} | ||
|
||
#[repr(C, align(2))] | ||
struct PartialDrop { | ||
a: HasDrop, | ||
b: u8, | ||
} | ||
|
||
//@error-pattern: /alignment 2 is required/ | ||
fn main() { | ||
unsafe { | ||
// Create an unaligned pointer | ||
let mut x = [0_u16; 2]; | ||
let p = core::ptr::addr_of_mut!(x).cast::<u8>(); | ||
let p = p.add(1); | ||
let p = p.cast::<PartialDrop>(); | ||
|
||
core::ptr::drop_in_place(p); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/tools/miri/tests/fail/unaligned_pointers/drop_in_place.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
error: Undefined Behavior: accessing memory with alignment ALIGN, but alignment ALIGN is required | ||
--> RUSTLIB/core/src/ptr/mod.rs:LL:CC | ||
| | ||
LL | pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ accessing memory with alignment ALIGN, but alignment ALIGN is required | ||
| | ||
= 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 `std::ptr::drop_in_place::<PartialDrop> - shim(Some(PartialDrop))` at RUSTLIB/core/src/ptr/mod.rs:LL:CC | ||
note: inside `main` | ||
--> $DIR/drop_in_place.rs:LL:CC | ||
| | ||
LL | core::ptr::drop_in_place(p); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace | ||
|
||
error: aborting due to previous error | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is the key change in the MIR spec here. It reflects what the codegen backends already do.