Skip to content

Commit 4aa1112

Browse files
committed
interpret: fix in-place return place semantics when the return place expression is a local variable
1 parent ef4d6ab commit 4aa1112

10 files changed

+37
-37
lines changed

tests/fail/function_calls/return_pointer_aliasing_read.none.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ LL | unsafe { ptr.read() };
1111
note: inside `main`
1212
--> tests/fail/function_calls/return_pointer_aliasing_read.rs:LL:CC
1313
|
14-
LL | Call(*ptr = myfun(ptr), ReturnTo(after_call), UnwindContinue())
15-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
LL | Call(_x = myfun(ptr), ReturnTo(after_call), UnwindContinue())
15+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1616

1717
Uninitialized memory occurred at ALLOC[0x0..0x4], in this allocation:
1818
ALLOC (stack variable, size: 4, align: 4) {

tests/fail/function_calls/return_pointer_aliasing_read.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ use std::intrinsics::mir::*;
1010
pub fn main() {
1111
mir! {
1212
{
13-
let x = 0;
14-
let ptr = &raw mut x;
13+
let _x = 0;
14+
let ptr = &raw mut _x;
1515
// We arrange for `myfun` to have a pointer that aliases
1616
// its return place. Even just reading from that pointer is UB.
17-
Call(*ptr = myfun(ptr), ReturnTo(after_call), UnwindContinue())
17+
Call(_x = myfun(ptr), ReturnTo(after_call), UnwindContinue())
1818
}
1919

2020
after_call = {
@@ -25,7 +25,7 @@ pub fn main() {
2525

2626
fn myfun(ptr: *mut i32) -> i32 {
2727
unsafe { ptr.read() };
28-
//~[stack]^ ERROR: not granting access
28+
//~[stack]^ ERROR: does not exist in the borrow stack
2929
//~[tree]| ERROR: /read access .* forbidden/
3030
//~[none]| ERROR: uninitialized
3131
// Without an aliasing model, reads are "fine" but at least they return uninit data.

tests/fail/function_calls/return_pointer_aliasing_read.stack.stderr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: Undefined Behavior: not granting access to tag <TAG> because that would remove [Unique for <TAG>] which is strongly protected
1+
error: Undefined Behavior: attempting a read access using <TAG> at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
22
--> tests/fail/function_calls/return_pointer_aliasing_read.rs:LL:CC
33
|
44
LL | unsafe { ptr.read() };
5-
| ^^^^^^^^^^ Undefined Behavior occurred here
5+
| ^^^^^^^^^^ this error occurs as part of an access at ALLOC[0x0..0x4]
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
@@ -11,12 +11,12 @@ help: <TAG> was created by a SharedReadWrite retag at offsets [0x0..0x4]
1111
|
1212
LL | / mir! {
1313
LL | | {
14-
LL | | let x = 0;
15-
LL | | let ptr = &raw mut x;
14+
LL | | let _x = 0;
15+
LL | | let ptr = &raw mut _x;
1616
... |
1717
LL | | }
1818
| |_____^
19-
help: <TAG> is this argument
19+
help: <TAG> was later invalidated at offsets [0x0..0x4] by a Unique in-place function argument/return passing protection
2020
--> tests/fail/function_calls/return_pointer_aliasing_read.rs:LL:CC
2121
|
2222
LL | unsafe { ptr.read() };
@@ -26,8 +26,8 @@ LL | unsafe { ptr.read() };
2626
note: inside `main`
2727
--> tests/fail/function_calls/return_pointer_aliasing_read.rs:LL:CC
2828
|
29-
LL | Call(*ptr = myfun(ptr), ReturnTo(after_call), UnwindContinue())
30-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
29+
LL | Call(_x = myfun(ptr), ReturnTo(after_call), UnwindContinue())
30+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3131
= 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)
3232

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

tests/fail/function_calls/return_pointer_aliasing_read.tree.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ help: the accessed tag <TAG> was created here
1313
|
1414
LL | / mir! {
1515
LL | | {
16-
LL | | let x = 0;
17-
LL | | let ptr = &raw mut x;
16+
LL | | let _x = 0;
17+
LL | | let ptr = &raw mut _x;
1818
... |
1919
LL | | }
2020
| |_____^
@@ -34,8 +34,8 @@ LL | unsafe { ptr.read() };
3434
note: inside `main`
3535
--> tests/fail/function_calls/return_pointer_aliasing_read.rs:LL:CC
3636
|
37-
LL | Call(*ptr = myfun(ptr), ReturnTo(after_call), UnwindContinue())
38-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
37+
LL | Call(_x = myfun(ptr), ReturnTo(after_call), UnwindContinue())
38+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3939
= 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)
4040

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

tests/fail/function_calls/return_pointer_aliasing_write.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub fn main() {
1414
let ptr = &raw mut _x;
1515
// We arrange for `myfun` to have a pointer that aliases
1616
// its return place. Writing to that pointer is UB.
17-
Call(*ptr = myfun(ptr), ReturnTo(after_call), UnwindContinue())
17+
Call(_x = myfun(ptr), ReturnTo(after_call), UnwindContinue())
1818
}
1919

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

tests/fail/function_calls/return_pointer_aliasing_write.stack.stderr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: Undefined Behavior: not granting access to tag <TAG> because that would remove [Unique for <TAG>] which is strongly protected
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
22
--> tests/fail/function_calls/return_pointer_aliasing_write.rs:LL:CC
33
|
44
LL | unsafe { ptr.write(0) };
5-
| ^^^^^^^^^^^^ Undefined Behavior occurred here
5+
| ^^^^^^^^^^^^ this error occurs as part of an access at ALLOC[0x0..0x4]
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
@@ -16,7 +16,7 @@ LL | | let ptr = &raw mut _x;
1616
... |
1717
LL | | }
1818
| |_____^
19-
help: <TAG> is this argument
19+
help: <TAG> was later invalidated at offsets [0x0..0x4] by a Unique in-place function argument/return passing protection
2020
--> tests/fail/function_calls/return_pointer_aliasing_write.rs:LL:CC
2121
|
2222
LL | unsafe { ptr.write(0) };
@@ -26,8 +26,8 @@ LL | unsafe { ptr.write(0) };
2626
note: inside `main`
2727
--> tests/fail/function_calls/return_pointer_aliasing_write.rs:LL:CC
2828
|
29-
LL | Call(*ptr = myfun(ptr), ReturnTo(after_call), UnwindContinue())
30-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
29+
LL | Call(_x = myfun(ptr), ReturnTo(after_call), UnwindContinue())
30+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3131
= 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)
3232

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

tests/fail/function_calls/return_pointer_aliasing_write.tree.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ LL | unsafe { ptr.write(0) };
3434
note: inside `main`
3535
--> tests/fail/function_calls/return_pointer_aliasing_write.rs:LL:CC
3636
|
37-
LL | Call(*ptr = myfun(ptr), ReturnTo(after_call), UnwindContinue())
38-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
37+
LL | Call(_x = myfun(ptr), ReturnTo(after_call), UnwindContinue())
38+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3939
= 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)
4040

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

tests/fail/function_calls/return_pointer_aliasing_write_tail_call.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub fn main() {
1616
let ptr = &raw mut _x;
1717
// We arrange for `myfun` to have a pointer that aliases
1818
// its return place. Writing to that pointer is UB.
19-
Call(*ptr = myfun(ptr), ReturnTo(after_call), UnwindContinue())
19+
Call(_x = myfun(ptr), ReturnTo(after_call), UnwindContinue())
2020
}
2121

2222
after_call = {
@@ -32,7 +32,7 @@ fn myfun(ptr: *mut i32) -> i32 {
3232
fn myfun2(ptr: *mut i32) -> i32 {
3333
// This overwrites the return place, which shouldn't be possible through another pointer.
3434
unsafe { ptr.write(0) };
35-
//~[stack]^ ERROR: strongly protected
35+
//~[stack]^ ERROR: does not exist in the borrow stack
3636
//~[tree]| ERROR: /write access .* forbidden/
3737
13
3838
}

tests/fail/function_calls/return_pointer_aliasing_write_tail_call.stack.stderr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: Undefined Behavior: not granting access to tag <TAG> because that would remove [Unique for <TAG>] which is strongly protected
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
22
--> tests/fail/function_calls/return_pointer_aliasing_write_tail_call.rs:LL:CC
33
|
44
LL | unsafe { ptr.write(0) };
5-
| ^^^^^^^^^^^^ Undefined Behavior occurred here
5+
| ^^^^^^^^^^^^ this error occurs as part of an access at ALLOC[0x0..0x4]
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
@@ -16,18 +16,18 @@ LL | | let ptr = &raw mut _x;
1616
... |
1717
LL | | }
1818
| |_____^
19-
help: <TAG> is this argument
19+
help: <TAG> was later invalidated at offsets [0x0..0x4] by a Unique in-place function argument/return passing protection
2020
--> tests/fail/function_calls/return_pointer_aliasing_write_tail_call.rs:LL:CC
2121
|
22-
LL | unsafe { ptr.write(0) };
23-
| ^^^^^^^^^^^^^^^^^^^^^^^
22+
LL | become myfun2(ptr)
23+
| ^^^^^^^^^^^^^^^^^^
2424
= note: BACKTRACE (of the first span):
2525
= note: inside `myfun2` at tests/fail/function_calls/return_pointer_aliasing_write_tail_call.rs:LL:CC
2626
note: inside `main`
2727
--> tests/fail/function_calls/return_pointer_aliasing_write_tail_call.rs:LL:CC
2828
|
29-
LL | Call(*ptr = myfun(ptr), ReturnTo(after_call), UnwindContinue())
30-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
29+
LL | Call(_x = myfun(ptr), ReturnTo(after_call), UnwindContinue())
30+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3131
= 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)
3232

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

tests/fail/function_calls/return_pointer_aliasing_write_tail_call.tree.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ LL | unsafe { ptr.write(0) };
3434
note: inside `main`
3535
--> tests/fail/function_calls/return_pointer_aliasing_write_tail_call.rs:LL:CC
3636
|
37-
LL | Call(*ptr = myfun(ptr), ReturnTo(after_call), UnwindContinue())
38-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
37+
LL | Call(_x = myfun(ptr), ReturnTo(after_call), UnwindContinue())
38+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3939
= 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)
4040

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

0 commit comments

Comments
 (0)