Skip to content

Commit ce946a6

Browse files
committed
Auto merge of #145599 - jieyouxu:rollup-523cxhm, r=jieyouxu
Rollup of 15 pull requests Successful merges: - rust-lang/rust#139345 (Extend `QueryStability` to handle `IntoIterator` implementations) - rust-lang/rust#140740 (Add `-Zindirect-branch-cs-prefix`) - rust-lang/rust#142079 (nll-relate: improve hr opaque types support) - rust-lang/rust#142938 (implement std::fs::set_permissions_nofollow on unix) - rust-lang/rust#143730 (fmt of non-decimal radix untangled) - rust-lang/rust#144767 (Correct some grammar in integer documentation) - rust-lang/rust#144906 (Require approval from t-infra instead of t-release on tier bumps) - rust-lang/rust#144983 (Rehome 37 `tests/ui/issues/` tests to other subdirectories under `tests/ui/`) - rust-lang/rust#145025 (run spellcheck as a tidy extra check in ci) - rust-lang/rust#145099 (rustc_target: Add the `32s` target feature for LoongArch) - rust-lang/rust#145166 (suggest using `pub(crate)` for E0364) - rust-lang/rust#145255 (dec2flt: Provide more valid inputs examples) - rust-lang/rust#145306 (Add tracing to various miscellaneous functions) - rust-lang/rust#145336 (Hide docs for `core::unicode`) - rust-lang/rust#145585 (Miri: fix handling of in-place argument and return place handling) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 09df8c7 + d58b7b9 commit ce946a6

14 files changed

+131
-37
lines changed

src/machine.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
11111111
) -> InterpResult<'tcx, Option<(&'tcx mir::Body<'tcx>, ty::Instance<'tcx>)>> {
11121112
// For foreign items, try to see if we can emulate them.
11131113
if ecx.tcx.is_foreign_item(instance.def_id()) {
1114+
let _trace = enter_trace_span!("emulate_foreign_item");
11141115
// An external function call that does not have a MIR body. We either find MIR elsewhere
11151116
// or emulate its effect.
11161117
// This will be Ok(None) if we're emulating the intrinsic entirely within Miri (no need
@@ -1123,6 +1124,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
11231124
}
11241125

11251126
// Otherwise, load the MIR.
1127+
let _trace = enter_trace_span!("load_mir");
11261128
interp_ok(Some((ecx.load_mir(instance.def, None)?, instance)))
11271129
}
11281130

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//@revisions: stack tree
2+
//@[tree]compile-flags: -Zmiri-tree-borrows
3+
// Validation forces more things into memory, which we can't have here.
4+
//@compile-flags: -Zmiri-disable-validation
5+
#![feature(custom_mir, core_intrinsics)]
6+
use std::intrinsics::mir::*;
7+
8+
pub struct S(i32);
9+
10+
#[custom_mir(dialect = "runtime", phase = "optimized")]
11+
fn main() {
12+
mir! {
13+
let _unit: ();
14+
{
15+
let staging = S(42); // This forces `staging` into memory...
16+
let non_copy = staging; // ... so we move it to a non-inmemory local here.
17+
// This specifically uses a type with scalar representation to tempt Miri to use the
18+
// efficient way of storing local variables (outside adressable memory).
19+
Call(_unit = callee(Move(non_copy), Move(non_copy)), ReturnTo(after_call), UnwindContinue())
20+
//~[stack]^ ERROR: not granting access
21+
//~[tree]| ERROR: /read access .* forbidden/
22+
}
23+
after_call = {
24+
Return()
25+
}
26+
}
27+
}
28+
29+
pub fn callee(x: S, mut y: S) {
30+
// With the setup above, if `x` and `y` are both moved,
31+
// then writing to `y` will change the value stored in `x`!
32+
y.0 = 0;
33+
assert_eq!(x.0, 42);
34+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
error: Undefined Behavior: not granting access to tag <TAG> because that would remove [Unique for <TAG>] which is strongly protected
2+
--> tests/fail/function_calls/arg_inplace_locals_alias.rs:LL:CC
3+
|
4+
LL | Call(_unit = callee(Move(non_copy), Move(non_copy)), ReturnTo(after_call), UnwindContinue())
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Undefined Behavior occurred here
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 here, as the root tag for ALLOC
10+
--> tests/fail/function_calls/arg_inplace_locals_alias.rs:LL:CC
11+
|
12+
LL | Call(_unit = callee(Move(non_copy), Move(non_copy)), ReturnTo(after_call), UnwindContinue())
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
help: <TAG> is this argument
15+
--> tests/fail/function_calls/arg_inplace_locals_alias.rs:LL:CC
16+
|
17+
LL | y.0 = 0;
18+
| ^^^^^^^
19+
= note: BACKTRACE (of the first span):
20+
= note: inside `main` at tests/fail/function_calls/arg_inplace_locals_alias.rs:LL:CC
21+
22+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
23+
24+
error: aborting due to 1 previous error
25+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
error: Undefined Behavior: read access through <TAG> (root of the allocation) at ALLOC[0x0] is forbidden
2+
--> tests/fail/function_calls/arg_inplace_locals_alias.rs:LL:CC
3+
|
4+
LL | Call(_unit = callee(Move(non_copy), Move(non_copy)), ReturnTo(after_call), UnwindContinue())
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Undefined Behavior occurred here
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 read 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+
--> tests/fail/function_calls/arg_inplace_locals_alias.rs:LL:CC
13+
|
14+
LL | Call(_unit = callee(Move(non_copy), Move(non_copy)), ReturnTo(after_call), UnwindContinue())
15+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16+
help: the protected tag <TAG> was created here, in the initial state Reserved
17+
--> tests/fail/function_calls/arg_inplace_locals_alias.rs:LL:CC
18+
|
19+
LL | y.0 = 0;
20+
| ^^^^^^^
21+
help: the protected tag <TAG> later transitioned to Active due to a child write access at offsets [0x0..0x4]
22+
--> tests/fail/function_calls/arg_inplace_locals_alias.rs:LL:CC
23+
|
24+
LL | y.0 = 0;
25+
| ^^^^^^^
26+
= help: this transition corresponds to the first write to a 2-phase borrowed mutable reference
27+
= note: BACKTRACE (of the first span):
28+
= note: inside `main` at tests/fail/function_calls/arg_inplace_locals_alias.rs:LL:CC
29+
30+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
31+
32+
error: aborting due to 1 previous error
33+

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

0 commit comments

Comments
 (0)