Skip to content

Commit fc132ae

Browse files
committed
Auto merge of #145796 - samueltardieu:rollup-linfi86, r=samueltardieu
Rollup of 14 pull requests Successful merges: - rust-lang/rust#143898 (opt-dist: rebuild rustc when doing static LLVM builds) - rust-lang/rust#144452 (std/sys/fd: Relax `READ_LIMIT` on Darwin) - rust-lang/rust#145234 (match exhaustiveness diagnostics: show a trailing comma on singleton tuple consructors in witness patterns (and clean up a little)) - rust-lang/rust#145515 (Optimize `char::encode_utf8`) - rust-lang/rust#145540 (interpret/allocation: get_range on ProvenanceMap) - rust-lang/rust#145670 (port `sanitize` attribute to the new parsing infrastructure) - rust-lang/rust#145713 (next-solver: fix `feature(const_trait_impl)` bootstrap) - rust-lang/rust#145729 (Remove two duplicated crates) - rust-lang/rust#145744 (miri: also detect aliasing of in-place argument and return place) - rust-lang/rust#145774 (Remove default opts from config) - rust-lang/rust#145781 (Remove profile section from Clippy) - rust-lang/rust#145782 (rustdoc: make attributes render consistently) - rust-lang/rust#145787 (citool: cleanup `mismatched_lifetime_syntaxes` warnings) - rust-lang/rust#145791 (Fix ICE when validating transmuting ZST to inhabited enum) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9f5cd5b + b328913 commit fc132ae

File tree

5 files changed

+98
-8
lines changed

5 files changed

+98
-8
lines changed

src/shims/native_lib/mod.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,9 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
242242

243243
match evt {
244244
AccessEvent::Read(_) => {
245-
// FIXME: ProvenanceMap should have something like get_range().
246-
let p_map = alloc.provenance();
247-
for idx in overlap {
248-
// If a provenance was read by the foreign code, expose it.
249-
if let Some((prov, _idx)) = p_map.get_byte(Size::from_bytes(idx), this)
250-
{
251-
this.expose_provenance(prov)?;
252-
}
245+
// If a provenance was read by the foreign code, expose it.
246+
for prov in alloc.provenance().get_range(this, overlap.into()) {
247+
this.expose_provenance(prov)?;
253248
}
254249
}
255250
AccessEvent::Write(_, certain) => {

tests/fail/function_calls/arg_inplace_locals_alias.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Ensure we detect aliasing of two in-place arguments for the tricky case where they do not
2+
//! live in memory.
13
//@revisions: stack tree
24
//@[tree]compile-flags: -Zmiri-tree-borrows
35
// Validation forces more things into memory, which we can't have here.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//! Ensure we detect aliasing of a in-place argument with the return place for the tricky case where
2+
//! they do not live in memory.
3+
//@revisions: stack tree
4+
//@[tree]compile-flags: -Zmiri-tree-borrows
5+
// Validation forces more things into memory, which we can't have here.
6+
//@compile-flags: -Zmiri-disable-validation
7+
#![feature(custom_mir, core_intrinsics)]
8+
use std::intrinsics::mir::*;
9+
10+
#[allow(unused)]
11+
pub struct S(i32);
12+
13+
#[custom_mir(dialect = "runtime", phase = "optimized")]
14+
fn main() {
15+
mir! {
16+
let _unit: ();
17+
{
18+
let staging = S(42); // This forces `staging` into memory...
19+
let _non_copy = staging; // ... so we move it to a non-inmemory local here.
20+
// This specifically uses a type with scalar representation to tempt Miri to use the
21+
// efficient way of storing local variables (outside adressable memory).
22+
Call(_non_copy = callee(Move(_non_copy)), ReturnTo(after_call), UnwindContinue())
23+
//~[stack]^ ERROR: not granting access
24+
//~[tree]| ERROR: /reborrow .* forbidden/
25+
}
26+
after_call = {
27+
Return()
28+
}
29+
}
30+
}
31+
32+
pub fn callee(x: S) -> S {
33+
x
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_ret.rs:LL:CC
3+
|
4+
LL | Call(_non_copy = callee(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_ret.rs:LL:CC
11+
|
12+
LL | Call(_non_copy = callee(Move(_non_copy)), ReturnTo(after_call), UnwindContinue())
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
help: <TAG> is this argument
15+
--> tests/fail/function_calls/arg_inplace_locals_alias_ret.rs:LL:CC
16+
|
17+
LL | x
18+
| ^
19+
= note: BACKTRACE (of the first span):
20+
= note: inside `main` at tests/fail/function_calls/arg_inplace_locals_alias_ret.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: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
error: Undefined Behavior: reborrow through <TAG> (root of the allocation) at ALLOC[0x0] is forbidden
2+
--> tests/fail/function_calls/arg_inplace_locals_alias_ret.rs:LL:CC
3+
|
4+
LL | Call(_non_copy = callee(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: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/tree-borrows.md for further information
9+
= help: the accessed tag <TAG> (root of the allocation) is foreign to the protected tag <TAG> (i.e., it is not a child)
10+
= help: this reborrow (acting as a foreign read access) would cause the protected tag <TAG> (currently Active) to become Disabled
11+
= help: protected tags must never be Disabled
12+
help: the accessed tag <TAG> was created here
13+
--> tests/fail/function_calls/arg_inplace_locals_alias_ret.rs:LL:CC
14+
|
15+
LL | Call(_non_copy = callee(Move(_non_copy)), ReturnTo(after_call), UnwindContinue())
16+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17+
help: the protected tag <TAG> was created here, in the initial state Reserved
18+
--> tests/fail/function_calls/arg_inplace_locals_alias_ret.rs:LL:CC
19+
|
20+
LL | x
21+
| ^
22+
help: the protected tag <TAG> later transitioned to Active due to a child write access at offsets [0x0..0x4]
23+
--> tests/fail/function_calls/arg_inplace_locals_alias_ret.rs:LL:CC
24+
|
25+
LL | x
26+
| ^
27+
= help: this transition corresponds to the first write to a 2-phase borrowed mutable reference
28+
= note: BACKTRACE (of the first span):
29+
= note: inside `main` at tests/fail/function_calls/arg_inplace_locals_alias_ret.rs:LL:CC
30+
31+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
32+
33+
error: aborting due to 1 previous error
34+

0 commit comments

Comments
 (0)