Skip to content

Commit b407a82

Browse files
author
The Miri Conjob Bot
committed
Merge from rustc
2 parents bbcc6fd + a778927 commit b407a82

File tree

9 files changed

+96
-9
lines changed

9 files changed

+96
-9
lines changed

src/machine.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -975,9 +975,9 @@ 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(ecx: &mut InterpCx<'mir, 'tcx, Self>, reason: mir::UnwindTerminateReason) -> InterpResult<'tcx> {
979979
// Call the lang item.
980-
let panic = ecx.tcx.lang_items().panic_cannot_unwind().unwrap();
980+
let panic = ecx.tcx.lang_items().get(reason.lang_item()).unwrap();
981981
let panic = ty::Instance::mono(ecx.tcx.tcx, panic);
982982
ecx.call_function(
983983
panic,
@@ -1405,4 +1405,22 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
14051405
}
14061406
res
14071407
}
1408+
1409+
fn after_local_allocated(
1410+
ecx: &mut InterpCx<'mir, 'tcx, Self>,
1411+
frame: usize,
1412+
local: mir::Local,
1413+
mplace: &MPlaceTy<'tcx, Provenance>
1414+
) -> InterpResult<'tcx> {
1415+
let Some(Provenance::Concrete { alloc_id, .. }) = mplace.ptr.provenance else {
1416+
panic!("after_local_allocated should only be called on fresh allocations");
1417+
};
1418+
let local_decl = &ecx.active_thread_stack()[frame].body.local_decls[local];
1419+
let span = local_decl.source_info.span;
1420+
ecx.machine
1421+
.allocation_spans
1422+
.borrow_mut()
1423+
.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)