Skip to content

Commit 476820c

Browse files
authored
Unrolled build for rust-lang#130245
Rollup merge of rust-lang#130245 - RalfJung:miri-alloc-backtrace, r=Amanieu make basic allocation functions track_caller in Miri for nicer backtraces This matches what we did with basic pointer and atomic operations.
2 parents 5e84295 + 03e8c95 commit 476820c

28 files changed

+79
-156
lines changed

library/alloc/src/alloc.rs

+13
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ pub use std::alloc::Global;
8989
#[stable(feature = "global_alloc", since = "1.28.0")]
9090
#[must_use = "losing the pointer will leak memory"]
9191
#[inline]
92+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
9293
pub unsafe fn alloc(layout: Layout) -> *mut u8 {
9394
unsafe {
9495
// Make sure we don't accidentally allow omitting the allocator shim in
@@ -113,6 +114,7 @@ pub unsafe fn alloc(layout: Layout) -> *mut u8 {
113114
/// See [`GlobalAlloc::dealloc`].
114115
#[stable(feature = "global_alloc", since = "1.28.0")]
115116
#[inline]
117+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
116118
pub unsafe fn dealloc(ptr: *mut u8, layout: Layout) {
117119
unsafe { __rust_dealloc(ptr, layout.size(), layout.align()) }
118120
}
@@ -132,6 +134,7 @@ pub unsafe fn dealloc(ptr: *mut u8, layout: Layout) {
132134
#[stable(feature = "global_alloc", since = "1.28.0")]
133135
#[must_use = "losing the pointer will leak memory"]
134136
#[inline]
137+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
135138
pub unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
136139
unsafe { __rust_realloc(ptr, layout.size(), layout.align(), new_size) }
137140
}
@@ -166,13 +169,15 @@ pub unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8
166169
#[stable(feature = "global_alloc", since = "1.28.0")]
167170
#[must_use = "losing the pointer will leak memory"]
168171
#[inline]
172+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
169173
pub unsafe fn alloc_zeroed(layout: Layout) -> *mut u8 {
170174
unsafe { __rust_alloc_zeroed(layout.size(), layout.align()) }
171175
}
172176

173177
#[cfg(not(test))]
174178
impl Global {
175179
#[inline]
180+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
176181
fn alloc_impl(&self, layout: Layout, zeroed: bool) -> Result<NonNull<[u8]>, AllocError> {
177182
match layout.size() {
178183
0 => Ok(NonNull::slice_from_raw_parts(layout.dangling(), 0)),
@@ -187,6 +192,7 @@ impl Global {
187192

188193
// SAFETY: Same as `Allocator::grow`
189194
#[inline]
195+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
190196
unsafe fn grow_impl(
191197
&self,
192198
ptr: NonNull<u8>,
@@ -237,16 +243,19 @@ impl Global {
237243
#[cfg(not(test))]
238244
unsafe impl Allocator for Global {
239245
#[inline]
246+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
240247
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
241248
self.alloc_impl(layout, false)
242249
}
243250

244251
#[inline]
252+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
245253
fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
246254
self.alloc_impl(layout, true)
247255
}
248256

249257
#[inline]
258+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
250259
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) {
251260
if layout.size() != 0 {
252261
// SAFETY: `layout` is non-zero in size,
@@ -256,6 +265,7 @@ unsafe impl Allocator for Global {
256265
}
257266

258267
#[inline]
268+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
259269
unsafe fn grow(
260270
&self,
261271
ptr: NonNull<u8>,
@@ -267,6 +277,7 @@ unsafe impl Allocator for Global {
267277
}
268278

269279
#[inline]
280+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
270281
unsafe fn grow_zeroed(
271282
&self,
272283
ptr: NonNull<u8>,
@@ -278,6 +289,7 @@ unsafe impl Allocator for Global {
278289
}
279290

280291
#[inline]
292+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
281293
unsafe fn shrink(
282294
&self,
283295
ptr: NonNull<u8>,
@@ -325,6 +337,7 @@ unsafe impl Allocator for Global {
325337
#[cfg(all(not(no_global_oom_handling), not(test)))]
326338
#[lang = "exchange_malloc"]
327339
#[inline]
340+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
328341
unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 {
329342
let layout = unsafe { Layout::from_size_align_unchecked(size, align) };
330343
match Global.allocate(layout) {

library/alloc/src/boxed.rs

+1
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ impl<T> Box<T> {
250250
#[stable(feature = "rust1", since = "1.0.0")]
251251
#[must_use]
252252
#[rustc_diagnostic_item = "box_new"]
253+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
253254
pub fn new(x: T) -> Self {
254255
#[rustc_box]
255256
Box::new(x)
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
use std::alloc::{alloc, dealloc, Layout};
22

3-
//@error-in-other-file: has size 1 and alignment 1, but gave size 1 and alignment 2
4-
53
fn main() {
64
unsafe {
75
let x = alloc(Layout::from_size_align_unchecked(1, 1));
8-
dealloc(x, Layout::from_size_align_unchecked(1, 2));
6+
dealloc(x, Layout::from_size_align_unchecked(1, 2)); //~ERROR: has size 1 and alignment 1, but gave size 1 and alignment 2
97
}
108
}

src/tools/miri/tests/fail/alloc/deallocate-bad-alignment.stderr

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
error: Undefined Behavior: incorrect layout on deallocation: ALLOC has size 1 and alignment ALIGN, but gave size 1 and alignment ALIGN
2-
--> RUSTLIB/alloc/src/alloc.rs:LL:CC
2+
--> $DIR/deallocate-bad-alignment.rs:LL:CC
33
|
4-
LL | unsafe { __rust_dealloc(ptr, layout.size(), layout.align()) }
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ incorrect layout on deallocation: ALLOC has size 1 and alignment ALIGN, but gave size 1 and alignment ALIGN
4+
LL | dealloc(x, Layout::from_size_align_unchecked(1, 2));
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ incorrect layout on deallocation: ALLOC has size 1 and alignment ALIGN, but gave size 1 and alignment ALIGN
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
99
= note: BACKTRACE:
10-
= note: inside `std::alloc::dealloc` at RUSTLIB/alloc/src/alloc.rs:LL:CC
11-
note: inside `main`
12-
--> $DIR/deallocate-bad-alignment.rs:LL:CC
13-
|
14-
LL | dealloc(x, Layout::from_size_align_unchecked(1, 2));
15-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10+
= note: inside `main` at $DIR/deallocate-bad-alignment.rs:LL:CC
1611

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

Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
use std::alloc::{alloc, dealloc, Layout};
22

3-
//@error-in-other-file: has size 1 and alignment 1, but gave size 2 and alignment 1
4-
53
fn main() {
64
unsafe {
75
let x = alloc(Layout::from_size_align_unchecked(1, 1));
8-
dealloc(x, Layout::from_size_align_unchecked(2, 1));
6+
dealloc(x, Layout::from_size_align_unchecked(2, 1)); //~ERROR: has size 1 and alignment 1, but gave size 2 and alignment 1
97
}
108
}

src/tools/miri/tests/fail/alloc/deallocate-bad-size.stderr

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
error: Undefined Behavior: incorrect layout on deallocation: ALLOC has size 1 and alignment ALIGN, but gave size 2 and alignment ALIGN
2-
--> RUSTLIB/alloc/src/alloc.rs:LL:CC
2+
--> $DIR/deallocate-bad-size.rs:LL:CC
33
|
4-
LL | unsafe { __rust_dealloc(ptr, layout.size(), layout.align()) }
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ incorrect layout on deallocation: ALLOC has size 1 and alignment ALIGN, but gave size 2 and alignment ALIGN
4+
LL | dealloc(x, Layout::from_size_align_unchecked(2, 1));
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ incorrect layout on deallocation: ALLOC has size 1 and alignment ALIGN, but gave size 2 and alignment ALIGN
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
99
= note: BACKTRACE:
10-
= note: inside `std::alloc::dealloc` at RUSTLIB/alloc/src/alloc.rs:LL:CC
11-
note: inside `main`
12-
--> $DIR/deallocate-bad-size.rs:LL:CC
13-
|
14-
LL | dealloc(x, Layout::from_size_align_unchecked(2, 1));
15-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10+
= note: inside `main` at $DIR/deallocate-bad-size.rs:LL:CC
1611

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

Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
use std::alloc::{alloc, dealloc, Layout};
22

3-
//@error-in-other-file: has been freed
4-
53
fn main() {
64
unsafe {
75
let x = alloc(Layout::from_size_align_unchecked(1, 1));
86
dealloc(x, Layout::from_size_align_unchecked(1, 1));
9-
dealloc(x, Layout::from_size_align_unchecked(1, 1));
7+
dealloc(x, Layout::from_size_align_unchecked(1, 1)); //~ERROR: has been freed
108
}
119
}

src/tools/miri/tests/fail/alloc/deallocate-twice.stderr

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: Undefined Behavior: memory access failed: ALLOC has been freed, so this pointer is dangling
2-
--> RUSTLIB/alloc/src/alloc.rs:LL:CC
2+
--> $DIR/deallocate-twice.rs:LL:CC
33
|
4-
LL | unsafe { __rust_dealloc(ptr, layout.size(), layout.align()) }
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: ALLOC has been freed, so this pointer is dangling
4+
LL | dealloc(x, Layout::from_size_align_unchecked(1, 1));
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: ALLOC has been freed, so this pointer is dangling
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
@@ -17,12 +17,7 @@ help: ALLOC was deallocated here:
1717
LL | dealloc(x, Layout::from_size_align_unchecked(1, 1));
1818
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1919
= note: BACKTRACE (of the first span):
20-
= note: inside `std::alloc::dealloc` at RUSTLIB/alloc/src/alloc.rs:LL:CC
21-
note: inside `main`
22-
--> $DIR/deallocate-twice.rs:LL:CC
23-
|
24-
LL | dealloc(x, Layout::from_size_align_unchecked(1, 1));
25-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20+
= note: inside `main` at $DIR/deallocate-twice.rs:LL:CC
2621

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

Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
use std::alloc::{alloc, realloc, Layout};
22

3-
//@error-in-other-file: has size 1 and alignment 1, but gave size 2 and alignment 1
4-
53
fn main() {
64
unsafe {
75
let x = alloc(Layout::from_size_align_unchecked(1, 1));
8-
let _y = realloc(x, Layout::from_size_align_unchecked(2, 1), 1);
6+
let _y = realloc(x, Layout::from_size_align_unchecked(2, 1), 1); //~ERROR: has size 1 and alignment 1, but gave size 2 and alignment 1
97
}
108
}

src/tools/miri/tests/fail/alloc/reallocate-bad-size.stderr

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
error: Undefined Behavior: incorrect layout on deallocation: ALLOC has size 1 and alignment ALIGN, but gave size 2 and alignment ALIGN
2-
--> RUSTLIB/alloc/src/alloc.rs:LL:CC
2+
--> $DIR/reallocate-bad-size.rs:LL:CC
33
|
4-
LL | unsafe { __rust_realloc(ptr, layout.size(), layout.align(), new_size) }
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ incorrect layout on deallocation: ALLOC has size 1 and alignment ALIGN, but gave size 2 and alignment ALIGN
4+
LL | let _y = realloc(x, Layout::from_size_align_unchecked(2, 1), 1);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ incorrect layout on deallocation: ALLOC has size 1 and alignment ALIGN, but gave size 2 and alignment ALIGN
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
99
= note: BACKTRACE:
10-
= note: inside `std::alloc::realloc` at RUSTLIB/alloc/src/alloc.rs:LL:CC
11-
note: inside `main`
12-
--> $DIR/reallocate-bad-size.rs:LL:CC
13-
|
14-
LL | let _y = realloc(x, Layout::from_size_align_unchecked(2, 1), 1);
15-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10+
= note: inside `main` at $DIR/reallocate-bad-size.rs:LL:CC
1611

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

Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
use std::alloc::{alloc, dealloc, realloc, Layout};
22

3-
//@error-in-other-file: has been freed
4-
53
fn main() {
64
unsafe {
75
let x = alloc(Layout::from_size_align_unchecked(1, 1));
86
dealloc(x, Layout::from_size_align_unchecked(1, 1));
9-
let _z = realloc(x, Layout::from_size_align_unchecked(1, 1), 1);
7+
let _z = realloc(x, Layout::from_size_align_unchecked(1, 1), 1); //~ERROR: has been freed
108
}
119
}

src/tools/miri/tests/fail/alloc/reallocate-dangling.stderr

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: Undefined Behavior: memory access failed: ALLOC has been freed, so this pointer is dangling
2-
--> RUSTLIB/alloc/src/alloc.rs:LL:CC
2+
--> $DIR/reallocate-dangling.rs:LL:CC
33
|
4-
LL | unsafe { __rust_realloc(ptr, layout.size(), layout.align(), new_size) }
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: ALLOC has been freed, so this pointer is dangling
4+
LL | let _z = realloc(x, Layout::from_size_align_unchecked(1, 1), 1);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: ALLOC has been freed, so this pointer is dangling
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
@@ -17,12 +17,7 @@ help: ALLOC was deallocated here:
1717
LL | dealloc(x, Layout::from_size_align_unchecked(1, 1));
1818
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1919
= note: BACKTRACE (of the first span):
20-
= note: inside `std::alloc::realloc` at RUSTLIB/alloc/src/alloc.rs:LL:CC
21-
note: inside `main`
22-
--> $DIR/reallocate-dangling.rs:LL:CC
23-
|
24-
LL | let _z = realloc(x, Layout::from_size_align_unchecked(1, 1), 1);
25-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20+
= note: inside `main` at $DIR/reallocate-dangling.rs:LL:CC
2621

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

src/tools/miri/tests/fail/alloc/stack_free.stderr

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
error: Undefined Behavior: deallocating ALLOC, which is stack variable memory, using Rust heap deallocation operation
2-
--> RUSTLIB/alloc/src/alloc.rs:LL:CC
2+
--> RUSTLIB/alloc/src/boxed.rs:LL:CC
33
|
4-
LL | unsafe { __rust_dealloc(ptr, layout.size(), layout.align()) }
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ deallocating ALLOC, which is stack variable memory, using Rust heap deallocation operation
4+
LL | self.1.deallocate(From::from(ptr.cast()), layout);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ deallocating ALLOC, which is stack variable memory, using Rust heap deallocation operation
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
99
= note: BACKTRACE:
10-
= note: inside `std::alloc::dealloc` at RUSTLIB/alloc/src/alloc.rs:LL:CC
11-
= note: inside `<std::alloc::Global as std::alloc::Allocator>::deallocate` at RUSTLIB/alloc/src/alloc.rs:LL:CC
1210
= note: inside `<std::boxed::Box<i32> as std::ops::Drop>::drop` at RUSTLIB/alloc/src/boxed.rs:LL:CC
1311
= note: inside `std::ptr::drop_in_place::<std::boxed::Box<i32>> - shim(Some(std::boxed::Box<i32>))` at RUSTLIB/core/src/ptr/mod.rs:LL:CC
1412
= note: inside `std::mem::drop::<std::boxed::Box<i32>>` at RUSTLIB/core/src/mem/mod.rs:LL:CC

src/tools/miri/tests/fail/both_borrows/newtype_pair_retagging.tree.stderr

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: Undefined Behavior: deallocation through <TAG> at ALLOC[0x0] is forbidden
2-
--> RUSTLIB/alloc/src/alloc.rs:LL:CC
2+
--> RUSTLIB/alloc/src/boxed.rs:LL:CC
33
|
4-
LL | unsafe { __rust_dealloc(ptr, layout.size(), layout.align()) }
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ deallocation through <TAG> at ALLOC[0x0] is forbidden
4+
LL | self.1.deallocate(From::from(ptr.cast()), layout);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ deallocation through <TAG> at ALLOC[0x0] is forbidden
66
|
77
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Tree Borrows rules it violated are still experimental
88
= help: the accessed tag <TAG> is foreign to the protected tag <TAG> (i.e., it is not a child)
@@ -25,8 +25,6 @@ LL | || drop(Box::from_raw(ptr)),
2525
| ^^^^^^^^^^^^^^^^^^
2626
= help: this transition corresponds to a temporary loss of write permissions until function exit
2727
= note: BACKTRACE (of the first span):
28-
= note: inside `std::alloc::dealloc` at RUSTLIB/alloc/src/alloc.rs:LL:CC
29-
= note: inside `<std::alloc::Global as std::alloc::Allocator>::deallocate` at RUSTLIB/alloc/src/alloc.rs:LL:CC
3028
= note: inside `<std::boxed::Box<i32> as std::ops::Drop>::drop` at RUSTLIB/alloc/src/boxed.rs:LL:CC
3129
= note: inside `std::ptr::drop_in_place::<std::boxed::Box<i32>> - shim(Some(std::boxed::Box<i32>))` at RUSTLIB/core/src/ptr/mod.rs:LL:CC
3230
= note: inside `std::mem::drop::<std::boxed::Box<i32>>` at RUSTLIB/core/src/mem/mod.rs:LL:CC

src/tools/miri/tests/fail/both_borrows/newtype_retagging.tree.stderr

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: Undefined Behavior: deallocation through <TAG> at ALLOC[0x0] is forbidden
2-
--> RUSTLIB/alloc/src/alloc.rs:LL:CC
2+
--> RUSTLIB/alloc/src/boxed.rs:LL:CC
33
|
4-
LL | unsafe { __rust_dealloc(ptr, layout.size(), layout.align()) }
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ deallocation through <TAG> at ALLOC[0x0] is forbidden
4+
LL | self.1.deallocate(From::from(ptr.cast()), layout);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ deallocation through <TAG> at ALLOC[0x0] is forbidden
66
|
77
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Tree Borrows rules it violated are still experimental
88
= help: the accessed tag <TAG> is foreign to the protected tag <TAG> (i.e., it is not a child)
@@ -25,8 +25,6 @@ LL | || drop(Box::from_raw(ptr)),
2525
| ^^^^^^^^^^^^^^^^^^
2626
= help: this transition corresponds to a temporary loss of write permissions until function exit
2727
= note: BACKTRACE (of the first span):
28-
= note: inside `std::alloc::dealloc` at RUSTLIB/alloc/src/alloc.rs:LL:CC
29-
= note: inside `<std::alloc::Global as std::alloc::Allocator>::deallocate` at RUSTLIB/alloc/src/alloc.rs:LL:CC
3028
= note: inside `<std::boxed::Box<i32> as std::ops::Drop>::drop` at RUSTLIB/alloc/src/boxed.rs:LL:CC
3129
= note: inside `std::ptr::drop_in_place::<std::boxed::Box<i32>> - shim(Some(std::boxed::Box<i32>))` at RUSTLIB/core/src/ptr/mod.rs:LL:CC
3230
= note: inside `std::mem::drop::<std::boxed::Box<i32>>` at RUSTLIB/core/src/mem/mod.rs:LL:CC

src/tools/miri/tests/fail/both_borrows/zero-sized-protected.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
//@revisions: stack tree
22
//@[tree]compile-flags: -Zmiri-tree-borrows
3-
//@[tree]error-in-other-file: /deallocation .* is forbidden/
43
use std::alloc::{alloc, dealloc, Layout};
54

65
// `x` is strongly protected but covers zero bytes.
76
// Let's see if deallocating the allocation x points to is UB:
87
// in TB, it is UB, but in SB it is not.
98
fn test(_x: &mut (), ptr: *mut u8, l: Layout) {
10-
unsafe { dealloc(ptr, l) };
9+
unsafe { dealloc(ptr, l) }; //~[tree] ERROR: /deallocation .* is forbidden/
1110
}
1211

1312
fn main() {

0 commit comments

Comments
 (0)