Skip to content

Commit 5b7bb23

Browse files
committed
Auto merge of #3038 - rust-lang:rustup-2023-08-26, r=RalfJung
Automatic sync from rustc
2 parents 0749bb5 + 84b4162 commit 5b7bb23

10 files changed

+97
-10
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
c40cfcf0494ff7506e753e750adb00eeea839f9c
1+
9334ec93541fd6963a3bfa2d2d09e3e33ac93131

src/machine.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -975,9 +975,12 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
975975
ecx.start_panic_nounwind(msg)
976976
}
977977

978-
fn unwind_terminate(ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx> {
978+
fn unwind_terminate(
979+
ecx: &mut InterpCx<'mir, 'tcx, Self>,
980+
reason: mir::UnwindTerminateReason,
981+
) -> InterpResult<'tcx> {
979982
// Call the lang item.
980-
let panic = ecx.tcx.lang_items().panic_cannot_unwind().unwrap();
983+
let panic = ecx.tcx.lang_items().get(reason.lang_item()).unwrap();
981984
let panic = ty::Instance::mono(ecx.tcx.tcx, panic);
982985
ecx.call_function(
983986
panic,
@@ -1405,4 +1408,19 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
14051408
}
14061409
res
14071410
}
1411+
1412+
fn after_local_allocated(
1413+
ecx: &mut InterpCx<'mir, 'tcx, Self>,
1414+
frame: usize,
1415+
local: mir::Local,
1416+
mplace: &MPlaceTy<'tcx, Provenance>,
1417+
) -> InterpResult<'tcx> {
1418+
let Some(Provenance::Concrete { alloc_id, .. }) = mplace.ptr.provenance else {
1419+
panic!("after_local_allocated should only be called on fresh allocations");
1420+
};
1421+
let local_decl = &ecx.active_thread_stack()[frame].body.local_decls[local];
1422+
let span = local_decl.source_info.span;
1423+
ecx.machine.allocation_spans.borrow_mut().insert(alloc_id, (span, None));
1424+
Ok(())
1425+
}
14081426
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// The interpreter tries to delay allocating locals until their address is taken.
2+
// This test checks that we correctly use the span associated with the local itself, not the span
3+
// where we take the address of the local and force it to be allocated.
4+
5+
fn main() {
6+
let ptr = {
7+
let x = 0usize; // This line should appear in the helps
8+
&x as *const usize // This line should NOT appear in the helps
9+
};
10+
unsafe {
11+
dbg!(*ptr); //~ ERROR: has been freed
12+
}
13+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error: Undefined Behavior: dereferencing pointer failed: ALLOC has been freed, so this pointer is dangling
2+
--> $DIR/dangling_primitive.rs:LL:CC
3+
|
4+
LL | dbg!(*ptr);
5+
| ^^^^^^^^^^ dereferencing pointer failed: ALLOC has been freed, so this pointer is dangling
6+
|
7+
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
8+
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9+
help: ALLOC was allocated here:
10+
--> $DIR/dangling_primitive.rs:LL:CC
11+
|
12+
LL | let x = 0usize; // This line should appear in the helps
13+
| ^
14+
help: ALLOC was deallocated here:
15+
--> $DIR/dangling_primitive.rs:LL:CC
16+
|
17+
LL | };
18+
| ^
19+
= note: BACKTRACE (of the first span):
20+
= note: inside `main` at RUSTLIB/std/src/macros.rs:LL:CC
21+
= note: this error originates in the macro `dbg` (in Nightly builds, run with -Z macro-backtrace for more info)
22+
23+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
24+
25+
error: aborting due to previous error
26+

tests/fail/dangling_pointers/deref-partially-dangling.stderr

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ LL | let val = unsafe { (*xptr).1 };
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
9-
= note: BACKTRACE:
9+
help: ALLOC was allocated here:
10+
--> $DIR/deref-partially-dangling.rs:LL:CC
11+
|
12+
LL | let x = (1, 13);
13+
| ^
14+
= note: BACKTRACE (of the first span):
1015
= note: inside `main` at $DIR/deref-partially-dangling.rs:LL:CC
1116

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

tests/fail/dangling_pointers/dyn_size.stderr

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ LL | let _ptr = unsafe { &*ptr };
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
9-
= note: BACKTRACE:
9+
help: ALLOC was allocated here:
10+
--> $DIR/dyn_size.rs:LL:CC
11+
|
12+
LL | let buf = [0u32; 1];
13+
| ^^^
14+
= note: BACKTRACE (of the first span):
1015
= note: inside `main` at $DIR/dyn_size.rs:LL:CC
1116

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

tests/fail/dangling_pointers/stack_temporary.stderr

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,17 @@ LL | let val = *x;
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
9-
= note: BACKTRACE:
9+
help: ALLOC was allocated here:
10+
--> $DIR/stack_temporary.rs:LL:CC
11+
|
12+
LL | let x = make_ref(&mut 0); // The temporary storing "0" is deallocated at the ";"!
13+
| ^
14+
help: ALLOC was deallocated here:
15+
--> $DIR/stack_temporary.rs:LL:CC
16+
|
17+
LL | let x = make_ref(&mut 0); // The temporary storing "0" is deallocated at the ";"!
18+
| ^
19+
= note: BACKTRACE (of the first span):
1020
= note: inside `main` at $DIR/stack_temporary.rs:LL:CC
1121

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

tests/fail/intrinsics/out_of_bounds_ptr_1.stderr

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ LL | let x = unsafe { x.offset(5) };
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
9-
= note: BACKTRACE:
9+
help: ALLOC was allocated here:
10+
--> $DIR/out_of_bounds_ptr_1.rs:LL:CC
11+
|
12+
LL | let v = [0i8; 4];
13+
| ^
14+
= note: BACKTRACE (of the first span):
1015
= note: inside `main` at $DIR/out_of_bounds_ptr_1.rs:LL:CC
1116

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

tests/fail/intrinsics/out_of_bounds_ptr_3.stderr

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ LL | let x = unsafe { x.offset(-1) };
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
9-
= note: BACKTRACE:
9+
help: ALLOC was allocated here:
10+
--> $DIR/out_of_bounds_ptr_3.rs:LL:CC
11+
|
12+
LL | let v = [0i8; 4];
13+
| ^
14+
= note: BACKTRACE (of the first span):
1015
= note: inside `main` at $DIR/out_of_bounds_ptr_3.rs:LL:CC
1116

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

tests/fail/panic/double_panic.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ thread 'main' panicked at $DIR/double_panic.rs:LL:CC:
55
second
66
stack backtrace:
77
thread 'main' panicked at RUSTLIB/core/src/panicking.rs:LL:CC:
8-
panic in a function that cannot unwind
8+
panic in a destructor during cleanup
99
stack backtrace:
1010
thread caused non-unwinding panic. aborting.
1111
error: abnormal termination: the program aborted execution
@@ -20,7 +20,7 @@ LL | ABORT();
2020
= note: inside `std::sys_common::backtrace::__rust_end_short_backtrace::<[closure@std::panicking::begin_panic_handler::{closure#0}], !>` at RUSTLIB/std/src/sys_common/backtrace.rs:LL:CC
2121
= note: inside `std::panicking::begin_panic_handler` at RUSTLIB/std/src/panicking.rs:LL:CC
2222
= note: inside `core::panicking::panic_nounwind` at RUSTLIB/core/src/panicking.rs:LL:CC
23-
= note: inside `core::panicking::panic_cannot_unwind` at RUSTLIB/core/src/panicking.rs:LL:CC
23+
= note: inside `core::panicking::panic_in_cleanup` at RUSTLIB/core/src/panicking.rs:LL:CC
2424
note: inside `main`
2525
--> $DIR/double_panic.rs:LL:CC
2626
|

0 commit comments

Comments
 (0)