Skip to content

Commit f41dcac

Browse files
committed
Auto merge of #3792 - RalfJung:test-typo, r=RalfJung
add and fix return-place-protection tests
2 parents a0b5e6b + a5c2936 commit f41dcac

10 files changed

+157
-39
lines changed

tests/fail/function_calls/return_pointer_aliasing.none.stderr renamed to tests/fail/function_calls/return_pointer_aliasing_read.none.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
2-
--> $DIR/return_pointer_aliasing.rs:LL:CC
2+
--> $DIR/return_pointer_aliasing_read.rs:LL:CC
33
|
44
LL | unsafe { ptr.read() };
55
| ^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
99
= note: BACKTRACE:
10-
= note: inside `myfun` at $DIR/return_pointer_aliasing.rs:LL:CC
10+
= note: inside `myfun` at $DIR/return_pointer_aliasing_read.rs:LL:CC
1111
note: inside `main`
12-
--> $DIR/return_pointer_aliasing.rs:LL:CC
12+
--> $DIR/return_pointer_aliasing_read.rs:LL:CC
1313
|
1414
LL | Call(*ptr = myfun(ptr), ReturnTo(after_call), UnwindContinue())
1515
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

tests/fail/function_calls/return_pointer_aliasing.stack.stderr renamed to tests/fail/function_calls/return_pointer_aliasing_read.stack.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
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
2-
--> $DIR/return_pointer_aliasing.rs:LL:CC
2+
--> $DIR/return_pointer_aliasing_read.rs:LL:CC
33
|
44
LL | unsafe { ptr.read() };
55
| ^^^^^^^^^^ 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
66
|
77
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
88
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
99
help: <TAG> was created by a SharedReadWrite retag at offsets [0x0..0x4]
10-
--> $DIR/return_pointer_aliasing.rs:LL:CC
10+
--> $DIR/return_pointer_aliasing_read.rs:LL:CC
1111
|
1212
LL | / mir! {
1313
LL | | {
@@ -18,14 +18,14 @@ LL | | }
1818
LL | | }
1919
| |_____^
2020
help: <TAG> is this argument
21-
--> $DIR/return_pointer_aliasing.rs:LL:CC
21+
--> $DIR/return_pointer_aliasing_read.rs:LL:CC
2222
|
2323
LL | unsafe { ptr.read() };
2424
| ^^^^^^^^^^^^^^^^^^^^^
2525
= note: BACKTRACE (of the first span):
26-
= note: inside `myfun` at $DIR/return_pointer_aliasing.rs:LL:CC
26+
= note: inside `myfun` at $DIR/return_pointer_aliasing_read.rs:LL:CC
2727
note: inside `main`
28-
--> $DIR/return_pointer_aliasing.rs:LL:CC
28+
--> $DIR/return_pointer_aliasing_read.rs:LL:CC
2929
|
3030
LL | Call(*ptr = myfun(ptr), ReturnTo(after_call), UnwindContinue())
3131
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

tests/fail/function_calls/return_pointer_aliasing.tree.stderr renamed to tests/fail/function_calls/return_pointer_aliasing_read.tree.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: Undefined Behavior: read access through <TAG> (root of the allocation) at ALLOC[0x0] is forbidden
2-
--> $DIR/return_pointer_aliasing.rs:LL:CC
2+
--> $DIR/return_pointer_aliasing_read.rs:LL:CC
33
|
44
LL | unsafe { ptr.read() };
55
| ^^^^^^^^^^ read access through <TAG> (root of the allocation) at ALLOC[0x0] is forbidden
@@ -9,7 +9,7 @@ LL | unsafe { ptr.read() };
99
= help: this foreign read access would cause the protected tag <TAG> (currently Active) to become Disabled
1010
= help: protected tags must never be Disabled
1111
help: the accessed tag <TAG> was created here
12-
--> $DIR/return_pointer_aliasing.rs:LL:CC
12+
--> $DIR/return_pointer_aliasing_read.rs:LL:CC
1313
|
1414
LL | / mir! {
1515
LL | | {
@@ -20,20 +20,20 @@ LL | | }
2020
LL | | }
2121
| |_____^
2222
help: the protected tag <TAG> was created here, in the initial state Reserved
23-
--> $DIR/return_pointer_aliasing.rs:LL:CC
23+
--> $DIR/return_pointer_aliasing_read.rs:LL:CC
2424
|
2525
LL | unsafe { ptr.read() };
2626
| ^^^^^^^^^^^^^^^^^^^^^
2727
help: the protected tag <TAG> later transitioned to Active due to a child write access at offsets [0x0..0x4]
28-
--> $DIR/return_pointer_aliasing.rs:LL:CC
28+
--> $DIR/return_pointer_aliasing_read.rs:LL:CC
2929
|
3030
LL | unsafe { ptr.read() };
3131
| ^^^^^^^^^^^^^^^^^^^^^
3232
= help: this transition corresponds to the first write to a 2-phase borrowed mutable reference
3333
= note: BACKTRACE (of the first span):
34-
= note: inside `myfun` at $DIR/return_pointer_aliasing.rs:LL:CC
34+
= note: inside `myfun` at $DIR/return_pointer_aliasing_read.rs:LL:CC
3535
note: inside `main`
36-
--> $DIR/return_pointer_aliasing.rs:LL:CC
36+
--> $DIR/return_pointer_aliasing_read.rs:LL:CC
3737
|
3838
LL | Call(*ptr = myfun(ptr), ReturnTo(after_call), UnwindContinue())
3939
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

tests/fail/function_calls/return_pointer_aliasing2.rs renamed to tests/fail/function_calls/return_pointer_aliasing_write.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This does need an aliasing model.
1+
// This does need an aliasing model and protectors.
22
//@revisions: stack tree
33
//@[tree]compile-flags: -Zmiri-tree-borrows
44
#![feature(raw_ref_op)]
@@ -14,8 +14,8 @@ pub fn main() {
1414
let _x = 0;
1515
let ptr = &raw mut _x;
1616
// We arrange for `myfun` to have a pointer that aliases
17-
// its return place. Even just reading from that pointer is UB.
18-
Call(_x = myfun(ptr), ReturnTo(after_call), UnwindContinue())
17+
// its return place. Writing to that pointer is UB.
18+
Call(*ptr = myfun(ptr), ReturnTo(after_call), UnwindContinue())
1919
}
2020

2121
after_call = {
@@ -27,7 +27,7 @@ pub fn main() {
2727
fn myfun(ptr: *mut i32) -> i32 {
2828
// This overwrites the return place, which shouldn't be possible through another pointer.
2929
unsafe { ptr.write(0) };
30-
//~[stack]^ ERROR: tag does not exist in the borrow stack
30+
//~[stack]^ ERROR: strongly protected
3131
//~[tree]| ERROR: /write access .* forbidden/
3232
13
3333
}

tests/fail/function_calls/return_pointer_aliasing2.stack.stderr renamed to tests/fail/function_calls/return_pointer_aliasing_write.stack.stderr

+10-13
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
error: Undefined Behavior: attempting a write access using <TAG> at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
2-
--> $DIR/return_pointer_aliasing2.rs:LL:CC
1+
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
2+
--> $DIR/return_pointer_aliasing_write.rs:LL:CC
33
|
44
LL | unsafe { ptr.write(0) };
5-
| ^^^^^^^^^^^^
6-
| |
7-
| attempting a write access using <TAG> at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
8-
| this error occurs as part of an access at ALLOC[0x0..0x4]
5+
| ^^^^^^^^^^^^ 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
96
|
107
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
118
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
129
help: <TAG> was created by a SharedReadWrite retag at offsets [0x0..0x4]
13-
--> $DIR/return_pointer_aliasing2.rs:LL:CC
10+
--> $DIR/return_pointer_aliasing_write.rs:LL:CC
1411
|
1512
LL | / mir! {
1613
LL | | {
@@ -20,18 +17,18 @@ LL | | let ptr = &raw mut _x;
2017
LL | | }
2118
LL | | }
2219
| |_____^
23-
help: <TAG> was later invalidated at offsets [0x0..0x4] by a Unique in-place function argument/return passing protection
24-
--> $DIR/return_pointer_aliasing2.rs:LL:CC
20+
help: <TAG> is this argument
21+
--> $DIR/return_pointer_aliasing_write.rs:LL:CC
2522
|
2623
LL | unsafe { ptr.write(0) };
2724
| ^^^^^^^^^^^^^^^^^^^^^^^
2825
= note: BACKTRACE (of the first span):
29-
= note: inside `myfun` at $DIR/return_pointer_aliasing2.rs:LL:CC
26+
= note: inside `myfun` at $DIR/return_pointer_aliasing_write.rs:LL:CC
3027
note: inside `main`
31-
--> $DIR/return_pointer_aliasing2.rs:LL:CC
28+
--> $DIR/return_pointer_aliasing_write.rs:LL:CC
3229
|
33-
LL | Call(_x = myfun(ptr), ReturnTo(after_call), UnwindContinue())
34-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
30+
LL | Call(*ptr = myfun(ptr), ReturnTo(after_call), UnwindContinue())
31+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3532
= 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)
3633

3734
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

tests/fail/function_calls/return_pointer_aliasing2.tree.stderr renamed to tests/fail/function_calls/return_pointer_aliasing_write.tree.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: Undefined Behavior: write access through <TAG> (root of the allocation) at ALLOC[0x0] is forbidden
2-
--> $DIR/return_pointer_aliasing2.rs:LL:CC
2+
--> $DIR/return_pointer_aliasing_write.rs:LL:CC
33
|
44
LL | unsafe { ptr.write(0) };
55
| ^^^^^^^^^^^^ write access through <TAG> (root of the allocation) at ALLOC[0x0] is forbidden
@@ -9,7 +9,7 @@ LL | unsafe { ptr.write(0) };
99
= help: this foreign write access would cause the protected tag <TAG> (currently Active) to become Disabled
1010
= help: protected tags must never be Disabled
1111
help: the accessed tag <TAG> was created here
12-
--> $DIR/return_pointer_aliasing2.rs:LL:CC
12+
--> $DIR/return_pointer_aliasing_write.rs:LL:CC
1313
|
1414
LL | / mir! {
1515
LL | | {
@@ -20,23 +20,23 @@ LL | | }
2020
LL | | }
2121
| |_____^
2222
help: the protected tag <TAG> was created here, in the initial state Reserved
23-
--> $DIR/return_pointer_aliasing2.rs:LL:CC
23+
--> $DIR/return_pointer_aliasing_write.rs:LL:CC
2424
|
2525
LL | unsafe { ptr.write(0) };
2626
| ^^^^^^^^^^^^^^^^^^^^^^^
2727
help: the protected tag <TAG> later transitioned to Active due to a child write access at offsets [0x0..0x4]
28-
--> $DIR/return_pointer_aliasing2.rs:LL:CC
28+
--> $DIR/return_pointer_aliasing_write.rs:LL:CC
2929
|
3030
LL | unsafe { ptr.write(0) };
3131
| ^^^^^^^^^^^^^^^^^^^^^^^
3232
= help: this transition corresponds to the first write to a 2-phase borrowed mutable reference
3333
= note: BACKTRACE (of the first span):
34-
= note: inside `myfun` at $DIR/return_pointer_aliasing2.rs:LL:CC
34+
= note: inside `myfun` at $DIR/return_pointer_aliasing_write.rs:LL:CC
3535
note: inside `main`
36-
--> $DIR/return_pointer_aliasing2.rs:LL:CC
36+
--> $DIR/return_pointer_aliasing_write.rs:LL:CC
3737
|
38-
LL | Call(_x = myfun(ptr), ReturnTo(after_call), UnwindContinue())
39-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
38+
LL | Call(*ptr = myfun(ptr), ReturnTo(after_call), UnwindContinue())
39+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4040
= 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)
4141

4242
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// This does need an aliasing model and protectors.
2+
//@revisions: stack tree
3+
//@[tree]compile-flags: -Zmiri-tree-borrows
4+
#![feature(raw_ref_op)]
5+
#![feature(core_intrinsics)]
6+
#![feature(custom_mir)]
7+
#![feature(explicit_tail_calls)]
8+
#![allow(incomplete_features)]
9+
10+
use std::intrinsics::mir::*;
11+
12+
#[custom_mir(dialect = "runtime", phase = "optimized")]
13+
pub fn main() {
14+
mir! {
15+
{
16+
let _x = 0;
17+
let ptr = &raw mut _x;
18+
// We arrange for `myfun` to have a pointer that aliases
19+
// its return place. Writing to that pointer is UB.
20+
Call(*ptr = myfun(ptr), ReturnTo(after_call), UnwindContinue())
21+
}
22+
23+
after_call = {
24+
Return()
25+
}
26+
}
27+
}
28+
29+
fn myfun(ptr: *mut i32) -> i32 {
30+
become myfun2(ptr)
31+
}
32+
33+
fn myfun2(ptr: *mut i32) -> i32 {
34+
// This overwrites the return place, which shouldn't be possible through another pointer.
35+
unsafe { ptr.write(0) };
36+
//~[stack]^ ERROR: strongly protected
37+
//~[tree]| ERROR: /write access .* forbidden/
38+
13
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
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
2+
--> $DIR/return_pointer_aliasing_write_tail_call.rs:LL:CC
3+
|
4+
LL | unsafe { ptr.write(0) };
5+
| ^^^^^^^^^^^^ 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
6+
|
7+
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
8+
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
9+
help: <TAG> was created by a SharedReadWrite retag at offsets [0x0..0x4]
10+
--> $DIR/return_pointer_aliasing_write_tail_call.rs:LL:CC
11+
|
12+
LL | / mir! {
13+
LL | | {
14+
LL | | let _x = 0;
15+
LL | | let ptr = &raw mut _x;
16+
... |
17+
LL | | }
18+
LL | | }
19+
| |_____^
20+
help: <TAG> is this argument
21+
--> $DIR/return_pointer_aliasing_write_tail_call.rs:LL:CC
22+
|
23+
LL | unsafe { ptr.write(0) };
24+
| ^^^^^^^^^^^^^^^^^^^^^^^
25+
= note: BACKTRACE (of the first span):
26+
= note: inside `myfun2` at $DIR/return_pointer_aliasing_write_tail_call.rs:LL:CC
27+
note: inside `main`
28+
--> $DIR/return_pointer_aliasing_write_tail_call.rs:LL:CC
29+
|
30+
LL | Call(*ptr = myfun(ptr), ReturnTo(after_call), UnwindContinue())
31+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
32+
= 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)
33+
34+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
35+
36+
error: aborting due to 1 previous error
37+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
error: Undefined Behavior: write access through <TAG> (root of the allocation) at ALLOC[0x0] is forbidden
2+
--> $DIR/return_pointer_aliasing_write_tail_call.rs:LL:CC
3+
|
4+
LL | unsafe { ptr.write(0) };
5+
| ^^^^^^^^^^^^ write access through <TAG> (root of the allocation) at ALLOC[0x0] is forbidden
6+
|
7+
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Tree Borrows rules it violated are still experimental
8+
= help: the accessed tag <TAG> (root of the allocation) is foreign to the protected tag <TAG> (i.e., it is not a child)
9+
= help: this foreign write access would cause the protected tag <TAG> (currently Active) to become Disabled
10+
= help: protected tags must never be Disabled
11+
help: the accessed tag <TAG> was created here
12+
--> $DIR/return_pointer_aliasing_write_tail_call.rs:LL:CC
13+
|
14+
LL | / mir! {
15+
LL | | {
16+
LL | | let _x = 0;
17+
LL | | let ptr = &raw mut _x;
18+
... |
19+
LL | | }
20+
LL | | }
21+
| |_____^
22+
help: the protected tag <TAG> was created here, in the initial state Reserved
23+
--> $DIR/return_pointer_aliasing_write_tail_call.rs:LL:CC
24+
|
25+
LL | unsafe { ptr.write(0) };
26+
| ^^^^^^^^^^^^^^^^^^^^^^^
27+
help: the protected tag <TAG> later transitioned to Active due to a child write access at offsets [0x0..0x4]
28+
--> $DIR/return_pointer_aliasing_write_tail_call.rs:LL:CC
29+
|
30+
LL | unsafe { ptr.write(0) };
31+
| ^^^^^^^^^^^^^^^^^^^^^^^
32+
= help: this transition corresponds to the first write to a 2-phase borrowed mutable reference
33+
= note: BACKTRACE (of the first span):
34+
= note: inside `myfun2` at $DIR/return_pointer_aliasing_write_tail_call.rs:LL:CC
35+
note: inside `main`
36+
--> $DIR/return_pointer_aliasing_write_tail_call.rs:LL:CC
37+
|
38+
LL | Call(*ptr = myfun(ptr), ReturnTo(after_call), UnwindContinue())
39+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
40+
= 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)
41+
42+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
43+
44+
error: aborting due to 1 previous error
45+

0 commit comments

Comments
 (0)