Skip to content

Commit f99343f

Browse files
committed
Auto merge of rust-lang#3030 - RalfJung:oob, r=saethlin
on out-of-bounds error, show where the allocation was created This seems useful, I think? r? `@saethlin`
2 parents 22f5aad + f71d76e commit f99343f

File tree

8 files changed

+46
-8
lines changed

8 files changed

+46
-8
lines changed

src/tools/miri/src/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ pub fn report_error<'tcx, 'mir>(
309309
(None, format!("this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior")),
310310
(None, format!("see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information")),
311311
];
312-
if let UndefinedBehaviorInfo::PointerUseAfterFree(alloc_id, _) = info {
312+
if let UndefinedBehaviorInfo::PointerUseAfterFree(alloc_id, _) | UndefinedBehaviorInfo::PointerOutOfBounds { alloc_id, .. } = info {
313313
if let Some(span) = ecx.machine.allocated_span(*alloc_id) {
314314
helps.push((Some(span), format!("{:?} was allocated here:", alloc_id)));
315315
}

src/tools/miri/tests/fail/both_borrows/issue-miri-1050-1.stack.stderr

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ LL | Box(unsafe { Unique::new_unchecked(raw) }, alloc)
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/issue-miri-1050-1.rs:LL:CC
11+
|
12+
LL | let ptr = Box::into_raw(Box::new(0u16));
13+
| ^^^^^^^^^^^^^^
14+
= note: BACKTRACE (of the first span):
1015
= note: inside `std::boxed::Box::<u32>::from_raw_in` at RUSTLIB/alloc/src/boxed.rs:LL:CC
1116
= note: inside `std::boxed::Box::<u32>::from_raw` at RUSTLIB/alloc/src/boxed.rs:LL:CC
1217
note: inside `main`

src/tools/miri/tests/fail/both_borrows/issue-miri-1050-1.tree.stderr

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ LL | Box(unsafe { Unique::new_unchecked(raw) }, alloc)
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/issue-miri-1050-1.rs:LL:CC
11+
|
12+
LL | let ptr = Box::into_raw(Box::new(0u16));
13+
| ^^^^^^^^^^^^^^
14+
= note: BACKTRACE (of the first span):
1015
= note: inside `std::boxed::Box::<u32>::from_raw_in` at RUSTLIB/alloc/src/boxed.rs:LL:CC
1116
= note: inside `std::boxed::Box::<u32>::from_raw` at RUSTLIB/alloc/src/boxed.rs:LL:CC
1217
note: inside `main`

src/tools/miri/tests/fail/dangling_pointers/out_of_bounds_read1.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@ LL | let x = unsafe { *v.as_ptr().wrapping_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_read1.rs:LL:CC
11+
|
12+
LL | let v: Vec<u8> = vec![1, 2];
13+
| ^^^^^^^^^^
14+
= note: BACKTRACE (of the first span):
1015
= note: inside `main` at $DIR/out_of_bounds_read1.rs:LL:CC
16+
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
1117

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

src/tools/miri/tests/fail/dangling_pointers/out_of_bounds_read2.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@ LL | let x = unsafe { *v.as_ptr().wrapping_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_read2.rs:LL:CC
11+
|
12+
LL | let v: Vec<u8> = vec![1, 2];
13+
| ^^^^^^^^^^
14+
= note: BACKTRACE (of the first span):
1015
= note: inside `main` at $DIR/out_of_bounds_read2.rs:LL:CC
16+
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
1117

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

src/tools/miri/tests/fail/intrinsics/ptr_offset_ptr_plus_0.stderr

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ LL | let _x = unsafe { x.offset(0) }; // UB despite offset 0, the pointer is
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/ptr_offset_ptr_plus_0.rs:LL:CC
11+
|
12+
LL | let x = Box::into_raw(Box::new(0u32));
13+
| ^^^^^^^^^^^^^^
14+
= note: BACKTRACE (of the first span):
1015
= note: inside `main` at $DIR/ptr_offset_ptr_plus_0.rs:LL:CC
1116

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

src/tools/miri/tests/fail/intrinsics/simd-scatter.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,14 @@ LL | | );
1111
|
1212
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
1313
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
14-
= note: BACKTRACE:
14+
help: ALLOC was allocated here:
15+
--> $DIR/simd-scatter.rs:LL:CC
16+
|
17+
LL | let mut vec: Vec<i8> = vec![10, 11, 12, 13, 14, 15, 16, 17, 18];
18+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19+
= note: BACKTRACE (of the first span):
1520
= note: inside `main` at $DIR/simd-scatter.rs:LL:CC
21+
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
1622

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

src/tools/miri/tests/fail/zst3.stderr

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ LL | unsafe { *(x as *mut [u8; 0]) = zst_val };
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/zst3.rs:LL:CC
11+
|
12+
LL | let mut x_box = Box::new(1u8);
13+
| ^^^^^^^^^^^^^
14+
= note: BACKTRACE (of the first span):
1015
= note: inside `main` at $DIR/zst3.rs:LL:CC
1116

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

0 commit comments

Comments
 (0)