forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#3792 - RalfJung:test-typo, r=RalfJung
add and fix return-place-protection tests
- Loading branch information
Showing
10 changed files
with
157 additions
and
39 deletions.
There are no files selected for viewing
6 changes: 3 additions & 3 deletions
6
...calls/return_pointer_aliasing.none.stderr → .../return_pointer_aliasing_read.none.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
File renamed without changes.
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
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
39 changes: 39 additions & 0 deletions
39
src/tools/miri/tests/fail/function_calls/return_pointer_aliasing_write_tail_call.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,39 @@ | ||
// This does need an aliasing model and protectors. | ||
//@revisions: stack tree | ||
//@[tree]compile-flags: -Zmiri-tree-borrows | ||
#![feature(raw_ref_op)] | ||
#![feature(core_intrinsics)] | ||
#![feature(custom_mir)] | ||
#![feature(explicit_tail_calls)] | ||
#![allow(incomplete_features)] | ||
|
||
use std::intrinsics::mir::*; | ||
|
||
#[custom_mir(dialect = "runtime", phase = "optimized")] | ||
pub fn main() { | ||
mir! { | ||
{ | ||
let _x = 0; | ||
let ptr = &raw mut _x; | ||
// We arrange for `myfun` to have a pointer that aliases | ||
// its return place. Writing to that pointer is UB. | ||
Call(*ptr = myfun(ptr), ReturnTo(after_call), UnwindContinue()) | ||
} | ||
|
||
after_call = { | ||
Return() | ||
} | ||
} | ||
} | ||
|
||
fn myfun(ptr: *mut i32) -> i32 { | ||
become myfun2(ptr) | ||
} | ||
|
||
fn myfun2(ptr: *mut i32) -> i32 { | ||
// This overwrites the return place, which shouldn't be possible through another pointer. | ||
unsafe { ptr.write(0) }; | ||
//~[stack]^ ERROR: strongly protected | ||
//~[tree]| ERROR: /write access .* forbidden/ | ||
13 | ||
} |
37 changes: 37 additions & 0 deletions
37
...tools/miri/tests/fail/function_calls/return_pointer_aliasing_write_tail_call.stack.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,37 @@ | ||
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/return_pointer_aliasing_write_tail_call.rs:LL:CC | ||
| | ||
LL | unsafe { ptr.write(0) }; | ||
| ^^^^^^^^^^^^ 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..0x4] | ||
--> $DIR/return_pointer_aliasing_write_tail_call.rs:LL:CC | ||
| | ||
LL | / mir! { | ||
LL | | { | ||
LL | | let _x = 0; | ||
LL | | let ptr = &raw mut _x; | ||
... | | ||
LL | | } | ||
LL | | } | ||
| |_____^ | ||
help: <TAG> is this argument | ||
--> $DIR/return_pointer_aliasing_write_tail_call.rs:LL:CC | ||
| | ||
LL | unsafe { ptr.write(0) }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
= note: BACKTRACE (of the first span): | ||
= note: inside `myfun2` at $DIR/return_pointer_aliasing_write_tail_call.rs:LL:CC | ||
note: inside `main` | ||
--> $DIR/return_pointer_aliasing_write_tail_call.rs:LL:CC | ||
| | ||
LL | Call(*ptr = myfun(ptr), ReturnTo(after_call), UnwindContinue()) | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
= note: this error originates in the macro `::core::intrinsics::mir::__internal_remove_let` which comes from the expansion of the macro `mir` (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 1 previous error | ||
|
45 changes: 45 additions & 0 deletions
45
src/tools/miri/tests/fail/function_calls/return_pointer_aliasing_write_tail_call.tree.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,45 @@ | ||
error: Undefined Behavior: write access through <TAG> (root of the allocation) at ALLOC[0x0] is forbidden | ||
--> $DIR/return_pointer_aliasing_write_tail_call.rs:LL:CC | ||
| | ||
LL | unsafe { ptr.write(0) }; | ||
| ^^^^^^^^^^^^ write access through <TAG> (root of the allocation) at ALLOC[0x0] is forbidden | ||
| | ||
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Tree Borrows rules it violated are still experimental | ||
= help: the accessed tag <TAG> (root of the allocation) is foreign to the protected tag <TAG> (i.e., it is not a child) | ||
= help: this foreign write access would cause the protected tag <TAG> (currently Active) to become Disabled | ||
= help: protected tags must never be Disabled | ||
help: the accessed tag <TAG> was created here | ||
--> $DIR/return_pointer_aliasing_write_tail_call.rs:LL:CC | ||
| | ||
LL | / mir! { | ||
LL | | { | ||
LL | | let _x = 0; | ||
LL | | let ptr = &raw mut _x; | ||
... | | ||
LL | | } | ||
LL | | } | ||
| |_____^ | ||
help: the protected tag <TAG> was created here, in the initial state Reserved | ||
--> $DIR/return_pointer_aliasing_write_tail_call.rs:LL:CC | ||
| | ||
LL | unsafe { ptr.write(0) }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
help: the protected tag <TAG> later transitioned to Active due to a child write access at offsets [0x0..0x4] | ||
--> $DIR/return_pointer_aliasing_write_tail_call.rs:LL:CC | ||
| | ||
LL | unsafe { ptr.write(0) }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
= help: this transition corresponds to the first write to a 2-phase borrowed mutable reference | ||
= note: BACKTRACE (of the first span): | ||
= note: inside `myfun2` at $DIR/return_pointer_aliasing_write_tail_call.rs:LL:CC | ||
note: inside `main` | ||
--> $DIR/return_pointer_aliasing_write_tail_call.rs:LL:CC | ||
| | ||
LL | Call(*ptr = myfun(ptr), ReturnTo(after_call), UnwindContinue()) | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
= note: this error originates in the macro `::core::intrinsics::mir::__internal_remove_let` which comes from the expansion of the macro `mir` (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 1 previous error | ||
|