diff --git a/src/tools/miri/src/helpers.rs b/src/tools/miri/src/helpers.rs index 2b27400e9e362..308455feaf619 100644 --- a/src/tools/miri/src/helpers.rs +++ b/src/tools/miri/src/helpers.rs @@ -919,7 +919,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { if fn_abi.conv != exp_abi { throw_ub_format!( "calling a function with ABI {:?} using caller ABI {:?}", - exp_abi, fn_abi.conv); + exp_abi, + fn_abi.conv + ); } interp_ok(()) } @@ -964,6 +966,21 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { return interp_ok(()); } + if ["__rust_alloc", "__rust_alloc_zeroed", "__rust_realloc", "__rust_dealloc"] + .contains(&link_name.as_str()) + { + let attrs = self.eval_context_ref().tcx.codegen_fn_attrs(instance.def_id()); + if attrs + .linkage + .map_or(false, |linkage| linkage == rustc_middle::mir::mono::Linkage::WeakAny) + && attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL) + { + // We intentionally intercept the allocator methods even though libstd provides + // default implementations. + return interp_ok(()); + } + } + throw_machine_stop!(TerminationInfo::SymbolShimClashing { link_name, span: body.span.data(), diff --git a/src/tools/miri/src/shims/alloc.rs b/src/tools/miri/src/shims/alloc.rs index 4dc9ba354a05a..25c0b52d0618b 100644 --- a/src/tools/miri/src/shims/alloc.rs +++ b/src/tools/miri/src/shims/alloc.rs @@ -1,6 +1,7 @@ use std::iter; use rustc_abi::{Align, Size}; +use rustc_ast::expand::allocator::AllocatorKind; use crate::*; @@ -51,6 +52,34 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { Align::from_bytes(prev_power_of_two(size)).unwrap() } + /// Emulates calling the internal __rust_* allocator functions + fn emulate_allocator( + &mut self, + default: impl FnOnce(&mut MiriInterpCx<'tcx>) -> InterpResult<'tcx>, + ) -> InterpResult<'tcx, EmulateItemResult> { + let this = self.eval_context_mut(); + + let Some(allocator_kind) = this.tcx.allocator_kind(()) else { + // in real code, this symbol does not exist without an allocator + return interp_ok(EmulateItemResult::NotSupported); + }; + + match allocator_kind { + AllocatorKind::Global => { + // When `#[global_allocator]` is used, `__rust_*` is defined by the macro expansion + // of this attribute. As such we have to call an exported Rust function, + // and not execute any Miri shim. Somewhat unintuitively doing so is done + // by returning `NotSupported`, which triggers the `lookup_exported_symbol` + // fallback case in `emulate_foreign_item`. + interp_ok(EmulateItemResult::NotSupported) + } + AllocatorKind::Default => { + default(this)?; + interp_ok(EmulateItemResult::NeedsReturn) + } + } + } + fn malloc(&mut self, size: u64, zero_init: bool) -> InterpResult<'tcx, Pointer> { let this = self.eval_context_mut(); let align = this.malloc_align(size); diff --git a/src/tools/miri/src/shims/foreign_items.rs b/src/tools/miri/src/shims/foreign_items.rs index 6ac7310ea2d2f..09c77267717e4 100644 --- a/src/tools/miri/src/shims/foreign_items.rs +++ b/src/tools/miri/src/shims/foreign_items.rs @@ -1,5 +1,6 @@ use std::collections::hash_map::Entry; use std::io::Write; +use std::iter; use std::path::Path; use rustc_abi::{Align, AlignFromBytesError, Size}; @@ -501,33 +502,124 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> { } // Rust allocation - "miri_alloc" => { - let [size, align] = this.check_shim(abi, Conv::Rust, link_name, args)?; - let size = this.read_target_usize(size)?; - let align = this.read_target_usize(align)?; + "__rust_alloc" | "miri_alloc" => { + let default = |ecx: &mut MiriInterpCx<'tcx>| { + // Only call `check_shim` when `#[global_allocator]` isn't used. When that + // macro is used, we act like no shim exists, so that the exported function can run. + let [size, align] = ecx.check_shim(abi, Conv::Rust, link_name, args)?; + let size = ecx.read_target_usize(size)?; + let align = ecx.read_target_usize(align)?; + + ecx.check_rustc_alloc_request(size, align)?; + + let memory_kind = match link_name.as_str() { + "__rust_alloc" => MiriMemoryKind::Rust, + "miri_alloc" => MiriMemoryKind::Miri, + _ => unreachable!(), + }; - this.check_rustc_alloc_request(size, align)?; + let ptr = ecx.allocate_ptr( + Size::from_bytes(size), + Align::from_bytes(align).unwrap(), + memory_kind.into(), + )?; - let ptr = this.allocate_ptr( - Size::from_bytes(size), - Align::from_bytes(align).unwrap(), - MiriMemoryKind::Miri.into(), - )?; + ecx.write_pointer(ptr, dest) + }; - this.write_pointer(ptr, dest)?; + match link_name.as_str() { + "__rust_alloc" => return this.emulate_allocator(default), + "miri_alloc" => { + default(this)?; + return interp_ok(EmulateItemResult::NeedsReturn); + } + _ => unreachable!(), + } } - "miri_dealloc" => { - let [ptr, old_size, align] = this.check_shim(abi, Conv::Rust, link_name, args)?; - let ptr = this.read_pointer(ptr)?; - let old_size = this.read_target_usize(old_size)?; - let align = this.read_target_usize(align)?; + "__rust_alloc_zeroed" => { + return this.emulate_allocator(|this| { + // See the comment for `__rust_alloc` why `check_shim` is only called in the + // default case. + let [size, align] = this.check_shim(abi, Conv::Rust, link_name, args)?; + let size = this.read_target_usize(size)?; + let align = this.read_target_usize(align)?; - // No need to check old_size/align; we anyway check that they match the allocation. - this.deallocate_ptr( - ptr, - Some((Size::from_bytes(old_size), Align::from_bytes(align).unwrap())), - MiriMemoryKind::Miri.into(), - )?; + this.check_rustc_alloc_request(size, align)?; + + let ptr = this.allocate_ptr( + Size::from_bytes(size), + Align::from_bytes(align).unwrap(), + MiriMemoryKind::Rust.into(), + )?; + + // We just allocated this, the access is definitely in-bounds. + this.write_bytes_ptr( + ptr.into(), + iter::repeat(0u8).take(usize::try_from(size).unwrap()), + ) + .unwrap(); + this.write_pointer(ptr, dest) + }); + } + "__rust_dealloc" | "miri_dealloc" => { + let default = |ecx: &mut MiriInterpCx<'tcx>| { + // See the comment for `__rust_alloc` why `check_shim` is only called in the + // default case. + let [ptr, old_size, align] = + ecx.check_shim(abi, Conv::Rust, link_name, args)?; + let ptr = ecx.read_pointer(ptr)?; + let old_size = ecx.read_target_usize(old_size)?; + let align = ecx.read_target_usize(align)?; + + let memory_kind = match link_name.as_str() { + "__rust_dealloc" => MiriMemoryKind::Rust, + "miri_dealloc" => MiriMemoryKind::Miri, + _ => unreachable!(), + }; + + // No need to check old_size/align; we anyway check that they match the allocation. + ecx.deallocate_ptr( + ptr, + Some((Size::from_bytes(old_size), Align::from_bytes(align).unwrap())), + memory_kind.into(), + ) + }; + + match link_name.as_str() { + "__rust_dealloc" => { + return this.emulate_allocator(default); + } + "miri_dealloc" => { + default(this)?; + return interp_ok(EmulateItemResult::NeedsReturn); + } + _ => unreachable!(), + } + } + "__rust_realloc" => { + return this.emulate_allocator(|this| { + // See the comment for `__rust_alloc` why `check_shim` is only called in the + // default case. + let [ptr, old_size, align, new_size] = + this.check_shim(abi, Conv::Rust, link_name, args)?; + let ptr = this.read_pointer(ptr)?; + let old_size = this.read_target_usize(old_size)?; + let align = this.read_target_usize(align)?; + let new_size = this.read_target_usize(new_size)?; + // No need to check old_size; we anyway check that they match the allocation. + + this.check_rustc_alloc_request(new_size, align)?; + + let align = Align::from_bytes(align).unwrap(); + let new_ptr = this.reallocate_ptr( + ptr, + Some((Size::from_bytes(old_size), align)), + Size::from_bytes(new_size), + align, + MiriMemoryKind::Rust.into(), + )?; + this.write_pointer(new_ptr, dest) + }); } // C memory handling functions diff --git a/src/tools/miri/tests/fail/alloc/deallocate-bad-alignment.stderr b/src/tools/miri/tests/fail/alloc/deallocate-bad-alignment.stderr new file mode 100644 index 0000000000000..f07db3c62c91d --- /dev/null +++ b/src/tools/miri/tests/fail/alloc/deallocate-bad-alignment.stderr @@ -0,0 +1,15 @@ +error: Undefined Behavior: incorrect layout on deallocation: ALLOC has size 1 and alignment ALIGN, but gave size 1 and alignment ALIGN + --> tests/fail/alloc/deallocate-bad-alignment.rs:LL:CC + | +LL | dealloc(x, Layout::from_size_align_unchecked(1, 2)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ incorrect layout on deallocation: ALLOC has size 1 and alignment ALIGN, but gave size 1 and alignment ALIGN + | + = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior + = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information + = note: BACKTRACE: + = note: inside `main` at tests/fail/alloc/deallocate-bad-alignment.rs:LL:CC + +note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace + +error: aborting due to 1 previous error + diff --git a/src/tools/miri/tests/fail/alloc/deallocate-bad-size.stderr b/src/tools/miri/tests/fail/alloc/deallocate-bad-size.stderr new file mode 100644 index 0000000000000..c913bde04cc91 --- /dev/null +++ b/src/tools/miri/tests/fail/alloc/deallocate-bad-size.stderr @@ -0,0 +1,15 @@ +error: Undefined Behavior: incorrect layout on deallocation: ALLOC has size 1 and alignment ALIGN, but gave size 2 and alignment ALIGN + --> tests/fail/alloc/deallocate-bad-size.rs:LL:CC + | +LL | dealloc(x, Layout::from_size_align_unchecked(2, 1)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ incorrect layout on deallocation: ALLOC has size 1 and alignment ALIGN, but gave size 2 and alignment ALIGN + | + = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior + = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information + = note: BACKTRACE: + = note: inside `main` at tests/fail/alloc/deallocate-bad-size.rs:LL:CC + +note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace + +error: aborting due to 1 previous error + diff --git a/src/tools/miri/tests/fail/alloc/deallocate-twice.stderr b/src/tools/miri/tests/fail/alloc/deallocate-twice.stderr index 344dd5689c6eb..9e6ce3d45a726 100644 --- a/src/tools/miri/tests/fail/alloc/deallocate-twice.stderr +++ b/src/tools/miri/tests/fail/alloc/deallocate-twice.stderr @@ -1,8 +1,8 @@ error: Undefined Behavior: memory access failed: ALLOC has been freed, so this pointer is dangling - --> RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC + --> tests/fail/alloc/deallocate-twice.rs:LL:CC | -LL | unsafe { libc::free(ptr as *mut libc::c_void) } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: ALLOC has been freed, so this pointer is dangling +LL | dealloc(x, Layout::from_size_align_unchecked(1, 1)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: ALLOC has been freed, so this pointer is dangling | = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information @@ -17,13 +17,7 @@ help: ALLOC was deallocated here: LL | dealloc(x, Layout::from_size_align_unchecked(1, 1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: BACKTRACE (of the first span): - = note: inside `std::sys::alloc::unix::::dealloc` at RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC - = note: inside `std::alloc::__default_lib_allocator::__rust_dealloc` at RUSTLIB/std/src/alloc.rs:LL:CC -note: inside `main` - --> tests/fail/alloc/deallocate-twice.rs:LL:CC - | -LL | dealloc(x, Layout::from_size_align_unchecked(1, 1)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: inside `main` at tests/fail/alloc/deallocate-twice.rs:LL:CC note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace diff --git a/src/tools/miri/tests/fail/alloc/global_system_mixup.stderr b/src/tools/miri/tests/fail/alloc/global_system_mixup.stderr new file mode 100644 index 0000000000000..4c355c511ef45 --- /dev/null +++ b/src/tools/miri/tests/fail/alloc/global_system_mixup.stderr @@ -0,0 +1,21 @@ +error: Undefined Behavior: deallocating ALLOC, which is Rust heap memory, using PLATFORM heap deallocation operation + --> RUSTLIB/std/src/sys/alloc/PLATFORM.rs:LL:CC + | +LL | FREE(); + | ^ deallocating ALLOC, which is Rust heap memory, using PLATFORM heap deallocation operation + | + = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior + = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information + = note: BACKTRACE: + = note: inside `std::sys::alloc::PLATFORM::::dealloc` at RUSTLIB/std/src/sys/alloc/PLATFORM.rs:LL:CC + = note: inside `::deallocate` at RUSTLIB/std/src/alloc.rs:LL:CC +note: inside `main` + --> tests/fail/alloc/global_system_mixup.rs:LL:CC + | +LL | unsafe { System.deallocate(ptr, l) }; + | ^ + +note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace + +error: aborting due to 1 previous error + diff --git a/src/tools/miri/tests/fail/alloc/reallocate-bad-size.stderr b/src/tools/miri/tests/fail/alloc/reallocate-bad-size.stderr index 24e97383b979a..6f6c8850603d4 100644 --- a/src/tools/miri/tests/fail/alloc/reallocate-bad-size.stderr +++ b/src/tools/miri/tests/fail/alloc/reallocate-bad-size.stderr @@ -1,21 +1,15 @@ -error: memory leaked: ALLOC (C heap, size: 1, align: 1), allocated here: - --> RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC +error: Undefined Behavior: incorrect layout on deallocation: ALLOC has size 1 and alignment ALIGN, but gave size 2 and alignment ALIGN + --> tests/fail/alloc/reallocate-bad-size.rs:LL:CC | -LL | unsafe { libc::realloc(ptr as *mut libc::c_void, new_size) as *mut u8 } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | let _y = realloc(x, Layout::from_size_align_unchecked(2, 1), 1); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ incorrect layout on deallocation: ALLOC has size 1 and alignment ALIGN, but gave size 2 and alignment ALIGN | + = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior + = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information = note: BACKTRACE: - = note: inside `std::sys::alloc::unix::::realloc` at RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC - = note: inside `std::alloc::__default_lib_allocator::__rust_realloc` at RUSTLIB/std/src/alloc.rs:LL:CC -note: inside `main` - --> tests/fail/alloc/reallocate-bad-size.rs:LL:CC - | -LL | ... let _y = realloc(x, Layout::from_size_align_unchecked(2, 1), 1); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: inside `main` at tests/fail/alloc/reallocate-bad-size.rs:LL:CC note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace -note: set `MIRIFLAGS=-Zmiri-ignore-leaks` to disable this check - error: aborting due to 1 previous error diff --git a/src/tools/miri/tests/fail/alloc/reallocate-dangling.stderr b/src/tools/miri/tests/fail/alloc/reallocate-dangling.stderr index dfe5cd024b512..06960380f6c94 100644 --- a/src/tools/miri/tests/fail/alloc/reallocate-dangling.stderr +++ b/src/tools/miri/tests/fail/alloc/reallocate-dangling.stderr @@ -1,8 +1,8 @@ error: Undefined Behavior: memory access failed: ALLOC has been freed, so this pointer is dangling - --> RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC + --> tests/fail/alloc/reallocate-dangling.rs:LL:CC | -LL | unsafe { libc::realloc(ptr as *mut libc::c_void, new_size) as *mut u8 } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: ALLOC has been freed, so this pointer is dangling +LL | let _z = realloc(x, Layout::from_size_align_unchecked(1, 1), 1); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: ALLOC has been freed, so this pointer is dangling | = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information @@ -17,13 +17,7 @@ help: ALLOC was deallocated here: LL | dealloc(x, Layout::from_size_align_unchecked(1, 1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: BACKTRACE (of the first span): - = note: inside `std::sys::alloc::unix::::realloc` at RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC - = note: inside `std::alloc::__default_lib_allocator::__rust_realloc` at RUSTLIB/std/src/alloc.rs:LL:CC -note: inside `main` - --> tests/fail/alloc/reallocate-dangling.rs:LL:CC - | -LL | let _z = realloc(x, Layout::from_size_align_unchecked(1, 1), 1); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: inside `main` at tests/fail/alloc/reallocate-dangling.rs:LL:CC note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace diff --git a/src/tools/miri/tests/fail/alloc/stack_free.stderr b/src/tools/miri/tests/fail/alloc/stack_free.stderr index 2885151e7113f..7d7cee133c653 100644 --- a/src/tools/miri/tests/fail/alloc/stack_free.stderr +++ b/src/tools/miri/tests/fail/alloc/stack_free.stderr @@ -1,14 +1,12 @@ -error: Undefined Behavior: deallocating ALLOC, which is stack variable memory, using C heap deallocation operation - --> RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC +error: Undefined Behavior: deallocating ALLOC, which is stack variable memory, using Rust heap deallocation operation + --> RUSTLIB/alloc/src/boxed.rs:LL:CC | -LL | unsafe { libc::free(ptr as *mut libc::c_void) } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ deallocating ALLOC, which is stack variable memory, using C heap deallocation operation +LL | self.1.deallocate(From::from(ptr.cast()), layout); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ deallocating ALLOC, which is stack variable memory, using Rust heap deallocation operation | = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information = note: BACKTRACE: - = note: inside `std::sys::alloc::unix::::dealloc` at RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC - = note: inside `std::alloc::__default_lib_allocator::__rust_dealloc` at RUSTLIB/std/src/alloc.rs:LL:CC = note: inside ` as std::ops::Drop>::drop` at RUSTLIB/alloc/src/boxed.rs:LL:CC = note: inside `std::ptr::drop_in_place::> - shim(Some(std::boxed::Box))` at RUSTLIB/core/src/ptr/mod.rs:LL:CC = note: inside `std::mem::drop::>` at RUSTLIB/core/src/mem/mod.rs:LL:CC diff --git a/src/tools/miri/tests/fail/alloc/too_large.stderr b/src/tools/miri/tests/fail/alloc/too_large.stderr index 3a3c239261903..03e54088e3b50 100644 --- a/src/tools/miri/tests/fail/alloc/too_large.stderr +++ b/src/tools/miri/tests/fail/alloc/too_large.stderr @@ -1,29 +1,13 @@ -thread 'main' panicked at RUSTLIB/core/src/panicking.rs:LL:CC: -unsafe precondition(s) violated: Layout::from_size_align_unchecked requires that align is a power of 2 and the rounded-up allocation size does not exceed isize::MAX -note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace -note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect -thread caused non-unwinding panic. aborting. -error: abnormal termination: the program aborted execution - --> RUSTLIB/std/src/sys/pal/PLATFORM/mod.rs:LL:CC - | -LL | unsafe { libc::abort() } - | ^^^^^^^^^^^^^ the program aborted execution - | - = note: BACKTRACE: - = note: inside `std::sys::pal::PLATFORM::abort_internal` at RUSTLIB/std/src/sys/pal/PLATFORM/mod.rs:LL:CC - = note: inside `std::panicking::rust_panic_with_hook` at RUSTLIB/std/src/panicking.rs:LL:CC - = note: inside closure at RUSTLIB/std/src/panicking.rs:LL:CC - = note: inside `std::sys::backtrace::__rust_end_short_backtrace::<{closure@std::panicking::begin_panic_handler::{closure#0}}, !>` at RUSTLIB/std/src/sys/backtrace.rs:LL:CC - = note: inside `std::panicking::begin_panic_handler` at RUSTLIB/std/src/panicking.rs:LL:CC - = note: inside `core::panicking::panic_nounwind` at RUSTLIB/core/src/panicking.rs:LL:CC - = note: inside `std::alloc::Layout::from_size_align_unchecked::precondition_check` at RUSTLIB/core/src/ub_checks.rs:LL:CC - = note: inside `std::alloc::Layout::from_size_align_unchecked` at RUSTLIB/core/src/ub_checks.rs:LL:CC - = note: inside `std::alloc::__default_lib_allocator::__rust_alloc` at RUSTLIB/std/src/alloc.rs:LL:CC -note: inside `main` +error: Undefined Behavior: creating an allocation larger than half the address space --> tests/fail/alloc/too_large.rs:LL:CC | LL | __rust_alloc(bytes, 1); - | ^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^ creating an allocation larger than half the address space + | + = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior + = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information + = note: BACKTRACE: + = note: inside `main` at tests/fail/alloc/too_large.rs:LL:CC note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace diff --git a/src/tools/miri/tests/fail/alloc/unsupported_big_alignment.stderr b/src/tools/miri/tests/fail/alloc/unsupported_big_alignment.stderr index 4bbda6c4ed846..8eb71f5ce8459 100644 --- a/src/tools/miri/tests/fail/alloc/unsupported_big_alignment.stderr +++ b/src/tools/miri/tests/fail/alloc/unsupported_big_alignment.stderr @@ -1,138 +1,14 @@ -thread 'rustc' panicked at src/tools/miri/src/shims/alloc.rs:LL:CC: -called `Result::unwrap()` on an `Err` value: `1073741824` is too large -stack backtrace: - 0: rust_begin_unwind - at RUSTLIB/std/src/panicking.rs:LL:CC - 1: core::panicking::panic_fmt - at RUSTLIB/core/src/panicking.rs:LL:CC - 2: core::result::unwrap_failed - at RUSTLIB/core/src/result.rs:LL:CC - 3: >::unwrap - at RUSTLIB/core/src/result.rs:LL:CC - 4: as miri::shims::alloc::EvalContextExt>::posix_memalign - at ./src/shims/alloc.rs:LL:CC - 5: as miri::shims::unix::foreign_items::EvalContextExt>::emulate_foreign_item_inner - at ./src/shims/unix/foreign_items.rs:LL:CC - 6: as miri::shims::foreign_items::EvalContextExtPriv>::emulate_foreign_item_inner - at ./src/shims/foreign_items.rs:LL:CC - 7: as miri::shims::foreign_items::EvalContextExt>::emulate_foreign_item - at ./src/shims/foreign_items.rs:LL:CC - 8: ::find_mir_or_eval_fn - at ./src/machine.rs:LL:CC - 9: >::init_fn_call - at /home/gh-bjorn3/rust/compiler/rustc_const_eval/src/interpret/call.rs:LL:CC - 10: >::eval_terminator - at /home/gh-bjorn3/rust/compiler/rustc_const_eval/src/interpret/step.rs:LL:CC - 11: >::step - at /home/gh-bjorn3/rust/compiler/rustc_const_eval/src/interpret/step.rs:LL:CC - 12: as miri::concurrency::thread::EvalContextExt>::run_threads - at ./src/concurrency/thread.rs:LL:CC - 13: miri::eval::eval_entry::{closure#0} - at ./src/eval.rs:LL:CC - 14: >::call_once - at RUSTLIB/core/src/ops/function.rs:LL:CC - 15: as core::ops::function::FnOnce<()>>::call_once - at RUSTLIB/core/src/panic/unwind_safe.rs:LL:CC - 16: std::panicking::try::do_call - at RUSTLIB/std/src/panicking.rs:LL:CC - 17: std::panicking::try - at RUSTLIB/std/src/panicking.rs:LL:CC - 18: std::panic::catch_unwind - at RUSTLIB/std/src/panic.rs:LL:CC - 19: miri::eval::eval_entry - at ./src/eval.rs:LL:CC - 20: ::after_analysis - at ./src/bin/miri.rs:LL:CC - 21: rustc_driver_impl::run_compiler::{closure#0}::{closure#2} - at /home/gh-bjorn3/rust/compiler/rustc_driver_impl/src/lib.rs:LL:CC - 22: rustc_interface::passes::create_and_enter_global_ctxt::{closure#2}::{closure#0} - at /home/gh-bjorn3/rust/compiler/rustc_interface/src/passes.rs:LL:CC - 23: ::create_global_ctxt::{closure#3} - at /home/gh-bjorn3/rust/compiler/rustc_middle/src/ty/context.rs:LL:CC - 24: rustc_middle::ty::context::tls::enter_context::{closure#0} - at /home/gh-bjorn3/rust/compiler/rustc_middle/src/ty/context/tls.rs:LL:CC - 25: >>::try_with - at RUSTLIB/std/src/thread/local.rs:LL:CC - 26: >>::with - at RUSTLIB/std/src/thread/local.rs:LL:CC - 27: rustc_middle::ty::context::tls::enter_context - at /home/gh-bjorn3/rust/compiler/rustc_middle/src/ty/context/tls.rs:LL:CC - 28: ::create_global_ctxt - at /home/gh-bjorn3/rust/compiler/rustc_middle/src/ty/context.rs:LL:CC - 29: rustc_interface::passes::create_and_enter_global_ctxt::{closure#2} - at /home/gh-bjorn3/rust/compiler/rustc_interface/src/passes.rs:LL:CC - 30: , rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core::ops::function::FnOnce<(&rustc_interface::interface::Compiler, &std::sync::once_lock::OnceLock, &rustc_data_structures::sync::worker_local::WorkerLocal, &rustc_data_structures::sync::worker_local::WorkerLocal, rustc_driver_impl::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0} - at RUSTLIB/core/src/ops/function.rs:LL:CC - 31: core::ops::function::FnOnce<(&'a rustc_interface::interface::Compiler, &'a std::sync::once_lock::OnceLock>, &'a rustc_data_structures::sync::worker_local::WorkerLocal>, &'a rustc_data_structures::sync::worker_local::WorkerLocal>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}), Output = core::option::Option>> as core::ops::function::FnOnce<(&rustc_interface::interface::Compiler, &std::sync::once_lock::OnceLock, &rustc_data_structures::sync::worker_local::WorkerLocal, &rustc_data_structures::sync::worker_local::WorkerLocal, rustc_driver_impl::run_compiler::{closure#0}::{closure#2})>>::call_once - at RUSTLIB/alloc/src/boxed.rs:LL:CC - 32: rustc_interface::passes::create_and_enter_global_ctxt - at /home/gh-bjorn3/rust/compiler/rustc_interface/src/passes.rs:LL:CC - 33: rustc_driver_impl::run_compiler::{closure#0} - at /home/gh-bjorn3/rust/compiler/rustc_driver_impl/src/lib.rs:LL:CC - 34: rustc_interface::interface::run_compiler::{closure#1}::{closure#0} - at /home/gh-bjorn3/rust/compiler/rustc_interface/src/interface.rs:LL:CC - 35: ::{closure#1}::{closure#0}> as core::ops::function::FnOnce<()>>::call_once - at RUSTLIB/core/src/panic/unwind_safe.rs:LL:CC - 36: std::panicking::try::do_call - at RUSTLIB/std/src/panicking.rs:LL:CC - 37: std::panicking::try - at RUSTLIB/std/src/panicking.rs:LL:CC - 38: std::panic::catch_unwind - at RUSTLIB/std/src/panic.rs:LL:CC - 39: rustc_interface::interface::run_compiler::{closure#1} - at /home/gh-bjorn3/rust/compiler/rustc_interface/src/interface.rs:LL:CC - 40: rustc_interface::util::run_in_thread_pool_with_globals::{closure#0} - at /home/gh-bjorn3/rust/compiler/rustc_interface/src/util.rs:LL:CC - 41: rustc_interface::util::run_in_thread_with_globals::{closure#0}::{closure#0}::{closure#0} - at /home/gh-bjorn3/rust/compiler/rustc_interface/src/util.rs:LL:CC - 42: >::set - at CARGO_REGISTRY/.../lib.rs:LL:CC - 43: rustc_span::create_session_globals_then - at /home/gh-bjorn3/rust/compiler/rustc_span/src/lib.rs:LL:CC - 44: rustc_interface::util::run_in_thread_with_globals::{closure#0}::{closure#0} - at /home/gh-bjorn3/rust/compiler/rustc_interface/src/util.rs:LL:CC -note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. - -error: the compiler unexpectedly panicked. this is a bug. - -note: we would appreciate a bug report: https://github.com/rust-lang/miri/issues/new - -note: please make sure that you have updated to the latest nightly - -note: please attach the file at `/home/gh-bjorn3/rust/src/tools/miri/rustc-ice-2024-12-20T10_31_46-710436.txt` to your bug report - -note: compiler flags: -Z ui-testing - -query stack during panic: -end of query stack - -Miri caused an ICE during evaluation. Here's the interpreter backtrace at the time of the panic: -note: the place in the program where the ICE was triggered - --> RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC - | -LL | let ret = unsafe { libc::posix_memalign(&mut out, align, layout.size()) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: BACKTRACE: - = note: inside `std::sys::alloc::unix::aligned_malloc` at RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC - = note: inside `std::sys::alloc::unix::::alloc` at RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC - = note: inside `std::alloc::__default_lib_allocator::__rust_alloc` at RUSTLIB/std/src/alloc.rs:LL:CC -note: inside `main` +error: unsupported operation: creating allocation with alignment ALIGN exceeding rustc's maximum supported value --> tests/fail/alloc/unsupported_big_alignment.rs:LL:CC | LL | __rust_alloc(1, 1 << 30); - | ^^^^^^^^^^^^^^^^^^^^^^^^ - = note: inside `>::call_once - shim(fn())` at RUSTLIB/core/src/ops/function.rs:LL:CC - = note: inside `std::sys::backtrace::__rust_begin_short_backtrace::` at RUSTLIB/std/src/sys/backtrace.rs:LL:CC - = note: inside closure at RUSTLIB/std/src/rt.rs:LL:CC - = note: inside `std::ops::function::impls:: for &dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe>::call_once` at RUSTLIB/core/src/ops/function.rs:LL:CC - = note: inside `std::panicking::r#try::do_call::<&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe, i32>` at RUSTLIB/std/src/panicking.rs:LL:CC - = note: inside `std::panicking::r#try:: i32 + std::marker::Sync + std::panic::RefUnwindSafe>` at RUSTLIB/std/src/panicking.rs:LL:CC - = note: inside `std::panic::catch_unwind::<&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe, i32>` at RUSTLIB/std/src/panic.rs:LL:CC - = note: inside closure at RUSTLIB/std/src/rt.rs:LL:CC - = note: inside `std::panicking::r#try::do_call::<{closure@std::rt::lang_start_internal::{closure#1}}, isize>` at RUSTLIB/std/src/panicking.rs:LL:CC - = note: inside `std::panicking::r#try::` at RUSTLIB/std/src/panicking.rs:LL:CC - = note: inside `std::panic::catch_unwind::<{closure@std::rt::lang_start_internal::{closure#1}}, isize>` at RUSTLIB/std/src/panic.rs:LL:CC - = note: inside `std::rt::lang_start_internal` at RUSTLIB/std/src/rt.rs:LL:CC - = note: inside `std::rt::lang_start::<()>` at RUSTLIB/std/src/rt.rs:LL:CC + | ^^^^^^^^^^^^^^^^^^^^^^^^ creating allocation with alignment ALIGN exceeding rustc's maximum supported value + | + = help: this is likely not a bug in the program; it indicates that the program performed an operation that Miri does not support + = note: BACKTRACE: + = note: inside `main` at tests/fail/alloc/unsupported_big_alignment.rs:LL:CC + +note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace + +error: aborting due to 1 previous error diff --git a/src/tools/miri/tests/fail/alloc/unsupported_non_power_two_alignment.stderr b/src/tools/miri/tests/fail/alloc/unsupported_non_power_two_alignment.stderr index b7cc9f1a64904..0a36d3d58b616 100644 --- a/src/tools/miri/tests/fail/alloc/unsupported_non_power_two_alignment.stderr +++ b/src/tools/miri/tests/fail/alloc/unsupported_non_power_two_alignment.stderr @@ -1,29 +1,13 @@ -thread 'main' panicked at RUSTLIB/core/src/panicking.rs:LL:CC: -unsafe precondition(s) violated: Layout::from_size_align_unchecked requires that align is a power of 2 and the rounded-up allocation size does not exceed isize::MAX -note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace -note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect -thread caused non-unwinding panic. aborting. -error: abnormal termination: the program aborted execution - --> RUSTLIB/std/src/sys/pal/PLATFORM/mod.rs:LL:CC - | -LL | unsafe { libc::abort() } - | ^^^^^^^^^^^^^ the program aborted execution - | - = note: BACKTRACE: - = note: inside `std::sys::pal::PLATFORM::abort_internal` at RUSTLIB/std/src/sys/pal/PLATFORM/mod.rs:LL:CC - = note: inside `std::panicking::rust_panic_with_hook` at RUSTLIB/std/src/panicking.rs:LL:CC - = note: inside closure at RUSTLIB/std/src/panicking.rs:LL:CC - = note: inside `std::sys::backtrace::__rust_end_short_backtrace::<{closure@std::panicking::begin_panic_handler::{closure#0}}, !>` at RUSTLIB/std/src/sys/backtrace.rs:LL:CC - = note: inside `std::panicking::begin_panic_handler` at RUSTLIB/std/src/panicking.rs:LL:CC - = note: inside `core::panicking::panic_nounwind` at RUSTLIB/core/src/panicking.rs:LL:CC - = note: inside `std::alloc::Layout::from_size_align_unchecked::precondition_check` at RUSTLIB/core/src/ub_checks.rs:LL:CC - = note: inside `std::alloc::Layout::from_size_align_unchecked` at RUSTLIB/core/src/ub_checks.rs:LL:CC - = note: inside `std::alloc::__default_lib_allocator::__rust_alloc` at RUSTLIB/std/src/alloc.rs:LL:CC -note: inside `main` +error: Undefined Behavior: creating allocation with non-power-of-two alignment ALIGN --> tests/fail/alloc/unsupported_non_power_two_alignment.rs:LL:CC | LL | __rust_alloc(1, 3); - | ^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^ creating allocation with non-power-of-two alignment ALIGN + | + = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior + = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information + = note: BACKTRACE: + = note: inside `main` at tests/fail/alloc/unsupported_non_power_two_alignment.rs:LL:CC note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace diff --git a/src/tools/miri/tests/fail/both_borrows/newtype_pair_retagging.tree.stderr b/src/tools/miri/tests/fail/both_borrows/newtype_pair_retagging.tree.stderr index 5e49ef214095a..ef1aa74ddf4ba 100644 --- a/src/tools/miri/tests/fail/both_borrows/newtype_pair_retagging.tree.stderr +++ b/src/tools/miri/tests/fail/both_borrows/newtype_pair_retagging.tree.stderr @@ -1,8 +1,8 @@ error: Undefined Behavior: deallocation through at ALLOC[0x0] is forbidden - --> RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC + --> RUSTLIB/alloc/src/boxed.rs:LL:CC | -LL | unsafe { libc::free(ptr as *mut libc::c_void) } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ deallocation through at ALLOC[0x0] is forbidden +LL | self.1.deallocate(From::from(ptr.cast()), layout); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ deallocation through at ALLOC[0x0] is forbidden | = help: this indicates a potential bug in the program: it performed an invalid operation, but the Tree Borrows rules it violated are still experimental = help: the accessed tag is foreign to the protected tag (i.e., it is not a child) @@ -25,8 +25,6 @@ LL | || drop(Box::from_raw(ptr)), | ^^^^^^^^^^^^^^^^^^ = help: this transition corresponds to a temporary loss of write permissions until function exit = note: BACKTRACE (of the first span): - = note: inside `std::sys::alloc::unix::::dealloc` at RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC - = note: inside `std::alloc::__default_lib_allocator::__rust_dealloc` at RUSTLIB/std/src/alloc.rs:LL:CC = note: inside ` as std::ops::Drop>::drop` at RUSTLIB/alloc/src/boxed.rs:LL:CC = note: inside `std::ptr::drop_in_place::> - shim(Some(std::boxed::Box))` at RUSTLIB/core/src/ptr/mod.rs:LL:CC = note: inside `std::mem::drop::>` at RUSTLIB/core/src/mem/mod.rs:LL:CC diff --git a/src/tools/miri/tests/fail/both_borrows/newtype_retagging.tree.stderr b/src/tools/miri/tests/fail/both_borrows/newtype_retagging.tree.stderr index 4b264a73dff6b..28fcd1411f962 100644 --- a/src/tools/miri/tests/fail/both_borrows/newtype_retagging.tree.stderr +++ b/src/tools/miri/tests/fail/both_borrows/newtype_retagging.tree.stderr @@ -1,8 +1,8 @@ error: Undefined Behavior: deallocation through at ALLOC[0x0] is forbidden - --> RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC + --> RUSTLIB/alloc/src/boxed.rs:LL:CC | -LL | unsafe { libc::free(ptr as *mut libc::c_void) } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ deallocation through at ALLOC[0x0] is forbidden +LL | self.1.deallocate(From::from(ptr.cast()), layout); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ deallocation through at ALLOC[0x0] is forbidden | = help: this indicates a potential bug in the program: it performed an invalid operation, but the Tree Borrows rules it violated are still experimental = help: the accessed tag is foreign to the protected tag (i.e., it is not a child) @@ -25,8 +25,6 @@ LL | || drop(Box::from_raw(ptr)), | ^^^^^^^^^^^^^^^^^^ = help: this transition corresponds to a temporary loss of write permissions until function exit = note: BACKTRACE (of the first span): - = note: inside `std::sys::alloc::unix::::dealloc` at RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC - = note: inside `std::alloc::__default_lib_allocator::__rust_dealloc` at RUSTLIB/std/src/alloc.rs:LL:CC = note: inside ` as std::ops::Drop>::drop` at RUSTLIB/alloc/src/boxed.rs:LL:CC = note: inside `std::ptr::drop_in_place::> - shim(Some(std::boxed::Box))` at RUSTLIB/core/src/ptr/mod.rs:LL:CC = note: inside `std::mem::drop::>` at RUSTLIB/core/src/mem/mod.rs:LL:CC diff --git a/src/tools/miri/tests/fail/both_borrows/zero-sized-protected.tree.stderr b/src/tools/miri/tests/fail/both_borrows/zero-sized-protected.tree.stderr index 48e84a8b04900..18d1fb6939540 100644 --- a/src/tools/miri/tests/fail/both_borrows/zero-sized-protected.tree.stderr +++ b/src/tools/miri/tests/fail/both_borrows/zero-sized-protected.tree.stderr @@ -1,8 +1,8 @@ error: Undefined Behavior: deallocation through (root of the allocation) at ALLOC[0x0] is forbidden - --> RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC + --> tests/fail/both_borrows/zero-sized-protected.rs:LL:CC | -LL | unsafe { libc::free(ptr as *mut libc::c_void) } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ deallocation through (root of the allocation) at ALLOC[0x0] is forbidden +LL | unsafe { dealloc(ptr, l) }; + | ^^^^^^^^^^^^^^^ deallocation through (root of the allocation) at ALLOC[0x0] is forbidden | = help: this indicates a potential bug in the program: it performed an invalid operation, but the Tree Borrows rules it violated are still experimental = help: the allocation of the accessed tag (root of the allocation) also contains the strongly protected tag @@ -18,13 +18,7 @@ help: the strongly protected tag was created here, in the initial state Re LL | fn test(_x: &mut (), ptr: *mut u8, l: Layout) { | ^^ = note: BACKTRACE (of the first span): - = note: inside `std::sys::alloc::unix::::dealloc` at RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC - = note: inside `std::alloc::__default_lib_allocator::__rust_dealloc` at RUSTLIB/std/src/alloc.rs:LL:CC -note: inside `test` - --> tests/fail/both_borrows/zero-sized-protected.rs:LL:CC - | -LL | unsafe { dealloc(ptr, l) }; - | ^^^^^^^^^^^^^^^ + = note: inside `test` at tests/fail/both_borrows/zero-sized-protected.rs:LL:CC note: inside `main` --> tests/fail/both_borrows/zero-sized-protected.rs:LL:CC | diff --git a/src/tools/miri/tests/fail/data_race/dealloc_read_race1.stderr b/src/tools/miri/tests/fail/data_race/dealloc_read_race1.stderr index 767a08e48de0f..8eb4ebbcf729d 100644 --- a/src/tools/miri/tests/fail/data_race/dealloc_read_race1.stderr +++ b/src/tools/miri/tests/fail/data_race/dealloc_read_race1.stderr @@ -1,8 +1,13 @@ error: Undefined Behavior: Data race detected between (1) non-atomic read on thread `unnamed-ID` and (2) deallocation on thread `unnamed-ID` at ALLOC. (2) just happened here - --> RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC + --> tests/fail/data_race/dealloc_read_race1.rs:LL:CC | -LL | unsafe { libc::free(ptr as *mut libc::c_void) } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Data race detected between (1) non-atomic read on thread `unnamed-ID` and (2) deallocation on thread `unnamed-ID` at ALLOC. (2) just happened here +LL | / __rust_dealloc( +LL | | +LL | | ptr.0 as *mut _, +LL | | std::mem::size_of::(), +LL | | std::mem::align_of::(), +LL | | ); + | |_____________^ Data race detected between (1) non-atomic read on thread `unnamed-ID` and (2) deallocation on thread `unnamed-ID` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> tests/fail/data_race/dealloc_read_race1.rs:LL:CC @@ -12,18 +17,7 @@ LL | let _val = *ptr.0; = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information = note: BACKTRACE (of the first span) on thread `unnamed-ID`: - = note: inside `std::sys::alloc::unix::::dealloc` at RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC - = note: inside `std::alloc::__default_lib_allocator::__rust_dealloc` at RUSTLIB/std/src/alloc.rs:LL:CC -note: inside closure - --> tests/fail/data_race/dealloc_read_race1.rs:LL:CC - | -LL | / __rust_dealloc( -LL | | -LL | | ptr.0 as *mut _, -LL | | std::mem::size_of::(), -LL | | std::mem::align_of::(), -LL | | ); - | |_____________^ + = note: inside closure at tests/fail/data_race/dealloc_read_race1.rs:LL:CC note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace diff --git a/src/tools/miri/tests/fail/data_race/dealloc_write_race1.stderr b/src/tools/miri/tests/fail/data_race/dealloc_write_race1.stderr index 9b9e3e40fe5a4..48d974241aada 100644 --- a/src/tools/miri/tests/fail/data_race/dealloc_write_race1.stderr +++ b/src/tools/miri/tests/fail/data_race/dealloc_write_race1.stderr @@ -1,8 +1,13 @@ error: Undefined Behavior: Data race detected between (1) non-atomic write on thread `unnamed-ID` and (2) deallocation on thread `unnamed-ID` at ALLOC. (2) just happened here - --> RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC + --> tests/fail/data_race/dealloc_write_race1.rs:LL:CC | -LL | unsafe { libc::free(ptr as *mut libc::c_void) } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Data race detected between (1) non-atomic write on thread `unnamed-ID` and (2) deallocation on thread `unnamed-ID` at ALLOC. (2) just happened here +LL | / __rust_dealloc( +LL | | +LL | | ptr.0 as *mut _, +LL | | std::mem::size_of::(), +LL | | std::mem::align_of::(), +LL | | ); + | |_____________^ Data race detected between (1) non-atomic write on thread `unnamed-ID` and (2) deallocation on thread `unnamed-ID` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> tests/fail/data_race/dealloc_write_race1.rs:LL:CC @@ -12,18 +17,7 @@ LL | *ptr.0 = 2; = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information = note: BACKTRACE (of the first span) on thread `unnamed-ID`: - = note: inside `std::sys::alloc::unix::::dealloc` at RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC - = note: inside `std::alloc::__default_lib_allocator::__rust_dealloc` at RUSTLIB/std/src/alloc.rs:LL:CC -note: inside closure - --> tests/fail/data_race/dealloc_write_race1.rs:LL:CC - | -LL | / __rust_dealloc( -LL | | -LL | | ptr.0 as *mut _, -LL | | std::mem::size_of::(), -LL | | std::mem::align_of::(), -LL | | ); - | |_____________^ + = note: inside closure at tests/fail/data_race/dealloc_write_race1.rs:LL:CC note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace diff --git a/src/tools/miri/tests/fail/memleak.stderr b/src/tools/miri/tests/fail/memleak.stderr index b73b79cba1bb7..89db0f1eb1628 100644 --- a/src/tools/miri/tests/fail/memleak.stderr +++ b/src/tools/miri/tests/fail/memleak.stderr @@ -1,17 +1,11 @@ -error: memory leaked: ALLOC (C heap, size: 4, align: 4), allocated here: - --> RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC - | -LL | unsafe { libc::malloc(layout.size()) as *mut u8 } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: BACKTRACE: - = note: inside `std::sys::alloc::unix::::alloc` at RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC - = note: inside `std::alloc::__default_lib_allocator::__rust_alloc` at RUSTLIB/std/src/alloc.rs:LL:CC -note: inside `main` +error: memory leaked: ALLOC (Rust heap, size: 4, align: 4), allocated here: --> tests/fail/memleak.rs:LL:CC | LL | std::mem::forget(Box::new(42)); | ^^^^^^^^^^^^ + | + = note: BACKTRACE: + = note: inside `main` at tests/fail/memleak.rs:LL:CC note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace diff --git a/src/tools/miri/tests/fail/memleak_no_backtrace.stderr b/src/tools/miri/tests/fail/memleak_no_backtrace.stderr index 5b9f73f5c61e7..6850928e1503c 100644 --- a/src/tools/miri/tests/fail/memleak_no_backtrace.stderr +++ b/src/tools/miri/tests/fail/memleak_no_backtrace.stderr @@ -1,4 +1,4 @@ -error: memory leaked: ALLOC (C heap, size: 4, align: 4) +error: memory leaked: ALLOC (Rust heap, size: 4, align: 4) note: set `MIRIFLAGS=-Zmiri-ignore-leaks` to disable this check diff --git a/src/tools/miri/tests/fail/memleak_rc.stderr b/src/tools/miri/tests/fail/memleak_rc.stderr index 07e4cf2bd5eb1..df12eeed6ac64 100644 --- a/src/tools/miri/tests/fail/memleak_rc.stderr +++ b/src/tools/miri/tests/fail/memleak_rc.stderr @@ -1,12 +1,10 @@ -error: memory leaked: ALLOC (C heap, size: 32, align: 16), allocated here: - --> RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC +error: memory leaked: ALLOC (Rust heap, SIZE, ALIGN), allocated here: + --> RUSTLIB/alloc/src/rc.rs:LL:CC | -LL | unsafe { libc::malloc(layout.size()) as *mut u8 } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | Box::leak(Box::new(RcInner { strong: Cell::new(1), weak: Cell::new(1), value })) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: BACKTRACE: - = note: inside `std::sys::alloc::unix::::alloc` at RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC - = note: inside `std::alloc::__default_lib_allocator::__rust_alloc` at RUSTLIB/std/src/alloc.rs:LL:CC = note: inside `std::rc::Rc::>>::new` at RUSTLIB/alloc/src/rc.rs:LL:CC note: inside `main` --> tests/fail/memleak_rc.rs:LL:CC diff --git a/src/tools/miri/tests/fail/stacked_borrows/deallocate_against_protector1.stderr b/src/tools/miri/tests/fail/stacked_borrows/deallocate_against_protector1.stderr index 5dd163ca5facf..f4cfa49c1564e 100644 --- a/src/tools/miri/tests/fail/stacked_borrows/deallocate_against_protector1.stderr +++ b/src/tools/miri/tests/fail/stacked_borrows/deallocate_against_protector1.stderr @@ -1,14 +1,12 @@ error: Undefined Behavior: deallocating while item [Unique for ] is strongly protected - --> RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC + --> RUSTLIB/alloc/src/boxed.rs:LL:CC | -LL | unsafe { libc::free(ptr as *mut libc::c_void) } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ deallocating while item [Unique for ] is strongly protected +LL | self.1.deallocate(From::from(ptr.cast()), layout); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ deallocating while item [Unique for ] is strongly protected | = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information = note: BACKTRACE: - = note: inside `std::sys::alloc::unix::::dealloc` at RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC - = note: inside `std::alloc::__default_lib_allocator::__rust_dealloc` at RUSTLIB/std/src/alloc.rs:LL:CC = note: inside ` as std::ops::Drop>::drop` at RUSTLIB/alloc/src/boxed.rs:LL:CC = note: inside `std::ptr::drop_in_place::> - shim(Some(std::boxed::Box))` at RUSTLIB/core/src/ptr/mod.rs:LL:CC = note: inside `std::mem::drop::>` at RUSTLIB/core/src/mem/mod.rs:LL:CC diff --git a/src/tools/miri/tests/fail/stacked_borrows/illegal_dealloc1.stderr b/src/tools/miri/tests/fail/stacked_borrows/illegal_dealloc1.stderr index 7459ffc9fba47..ddf8dbea31f59 100644 --- a/src/tools/miri/tests/fail/stacked_borrows/illegal_dealloc1.stderr +++ b/src/tools/miri/tests/fail/stacked_borrows/illegal_dealloc1.stderr @@ -1,8 +1,8 @@ error: Undefined Behavior: attempting deallocation using at ALLOC, but that tag does not exist in the borrow stack for this location - --> RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC + --> tests/fail/stacked_borrows/illegal_deALLOC.rs:LL:CC | -LL | unsafe { libc::free(ptr as *mut libc::c_void) } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempting deallocation using at ALLOC, but that tag does not exist in the borrow stack for this location +LL | dealloc(ptr2, Layout::from_size_align_unchecked(1, 1)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempting deallocation using at ALLOC, but that tag does not exist in the borrow stack for this location | = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information @@ -17,13 +17,7 @@ help: was later invalidated at offsets [0x0..0x1] by a write access LL | ptr1.write(0); | ^^^^^^^^^^^^^ = note: BACKTRACE (of the first span): - = note: inside `std::sys::alloc::unix::::dealloc` at RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC - = note: inside `std::alloc::__default_lib_allocator::__rust_dealloc` at RUSTLIB/std/src/alloc.rs:LL:CC -note: inside `main` - --> tests/fail/stacked_borrows/illegal_deALLOC.rs:LL:CC - | -LL | dealloc(ptr2, Layout::from_size_align_unchecked(1, 1)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: inside `main` at tests/fail/stacked_borrows/illegal_deALLOC.rs:LL:CC note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace diff --git a/src/tools/miri/tests/fail/tls_macro_leak.stderr b/src/tools/miri/tests/fail/tls_macro_leak.stderr index caac06ff4e4e9..512932b3cb8a6 100644 --- a/src/tools/miri/tests/fail/tls_macro_leak.stderr +++ b/src/tools/miri/tests/fail/tls_macro_leak.stderr @@ -1,17 +1,11 @@ -error: memory leaked: ALLOC (C heap, size: 4, align: 4), allocated here: - --> RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC - | -LL | unsafe { libc::malloc(layout.size()) as *mut u8 } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: BACKTRACE: - = note: inside `std::sys::alloc::unix::::alloc` at RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC - = note: inside `std::alloc::__default_lib_allocator::__rust_alloc` at RUSTLIB/std/src/alloc.rs:LL:CC -note: inside closure +error: memory leaked: ALLOC (Rust heap, size: 4, align: 4), allocated here: --> tests/fail/tls_macro_leak.rs:LL:CC | LL | cell.set(Some(Box::leak(Box::new(123)))); | ^^^^^^^^^^^^^ + | + = note: BACKTRACE: + = note: inside closure at tests/fail/tls_macro_leak.rs:LL:CC = note: inside `std::thread::LocalKey::>>::try_with::<{closure@tests/fail/tls_macro_leak.rs:LL:CC}, ()>` at RUSTLIB/std/src/thread/local.rs:LL:CC = note: inside `std::thread::LocalKey::>>::with::<{closure@tests/fail/tls_macro_leak.rs:LL:CC}, ()>` at RUSTLIB/std/src/thread/local.rs:LL:CC note: inside closure diff --git a/src/tools/miri/tests/fail/tls_static_leak.stderr b/src/tools/miri/tests/fail/tls_static_leak.stderr index 946a2927f67a8..24306cca7ffdd 100644 --- a/src/tools/miri/tests/fail/tls_static_leak.stderr +++ b/src/tools/miri/tests/fail/tls_static_leak.stderr @@ -1,17 +1,11 @@ -error: memory leaked: ALLOC (C heap, size: 4, align: 4), allocated here: - --> RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC - | -LL | unsafe { libc::malloc(layout.size()) as *mut u8 } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: BACKTRACE: - = note: inside `std::sys::alloc::unix::::alloc` at RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC - = note: inside `std::alloc::__default_lib_allocator::__rust_alloc` at RUSTLIB/std/src/alloc.rs:LL:CC -note: inside closure +error: memory leaked: ALLOC (Rust heap, size: 4, align: 4), allocated here: --> tests/fail/tls_static_leak.rs:LL:CC | LL | TLS.set(Some(Box::leak(Box::new(123)))); | ^^^^^^^^^^^^^ + | + = note: BACKTRACE: + = note: inside closure at tests/fail/tls_static_leak.rs:LL:CC note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace diff --git a/src/tools/miri/tests/fail/tree_borrows/strongly-protected.stderr b/src/tools/miri/tests/fail/tree_borrows/strongly-protected.stderr index f7066853827e8..f6197a2acb391 100644 --- a/src/tools/miri/tests/fail/tree_borrows/strongly-protected.stderr +++ b/src/tools/miri/tests/fail/tree_borrows/strongly-protected.stderr @@ -1,8 +1,8 @@ error: Undefined Behavior: deallocation through at ALLOC[0x0] is forbidden - --> RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC + --> RUSTLIB/alloc/src/boxed.rs:LL:CC | -LL | unsafe { libc::free(ptr as *mut libc::c_void) } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ deallocation through at ALLOC[0x0] is forbidden +LL | self.1.deallocate(From::from(ptr.cast()), layout); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ deallocation through at ALLOC[0x0] is forbidden | = help: this indicates a potential bug in the program: it performed an invalid operation, but the Tree Borrows rules it violated are still experimental = help: the allocation of the accessed tag also contains the strongly protected tag @@ -18,8 +18,6 @@ help: the strongly protected tag was created here, in the initial state Re LL | fn inner(x: &mut i32, f: fn(*mut i32)) { | ^ = note: BACKTRACE (of the first span): - = note: inside `std::sys::alloc::unix::::dealloc` at RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC - = note: inside `std::alloc::__default_lib_allocator::__rust_dealloc` at RUSTLIB/std/src/alloc.rs:LL:CC = note: inside ` as std::ops::Drop>::drop` at RUSTLIB/alloc/src/boxed.rs:LL:CC = note: inside `std::ptr::drop_in_place::> - shim(Some(std::boxed::Box))` at RUSTLIB/core/src/ptr/mod.rs:LL:CC = note: inside `std::mem::drop::>` at RUSTLIB/core/src/mem/mod.rs:LL:CC diff --git a/src/tools/miri/tests/fail/uninit/uninit_alloc_diagnostic.stderr b/src/tools/miri/tests/fail/uninit/uninit_alloc_diagnostic.stderr index 420b4e051affd..0996e5d11eff6 100644 --- a/src/tools/miri/tests/fail/uninit/uninit_alloc_diagnostic.stderr +++ b/src/tools/miri/tests/fail/uninit/uninit_alloc_diagnostic.stderr @@ -16,7 +16,7 @@ LL | drop(slice1.cmp(slice2)); | ^^^^^^^^^^^^^^^^^^ Uninitialized memory occurred at ALLOC[0x4..0x10], in this allocation: -ALLOC (C heap, size: 32, align: 16) { +ALLOC (Rust heap, size: 32, align: 8) { 0x00 │ 41 42 43 44 __ __ __ __ __ __ __ __ __ __ __ __ │ ABCD░░░░░░░░░░░░ 0x10 │ 00 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ │ .░░░░░░░░░░░░░░░ } diff --git a/src/tools/miri/tests/fail/uninit/uninit_alloc_diagnostic_with_provenance.stderr b/src/tools/miri/tests/fail/uninit/uninit_alloc_diagnostic_with_provenance.stderr index 59aae23a66c21..bcde9377c5400 100644 --- a/src/tools/miri/tests/fail/uninit/uninit_alloc_diagnostic_with_provenance.stderr +++ b/src/tools/miri/tests/fail/uninit/uninit_alloc_diagnostic_with_provenance.stderr @@ -16,7 +16,7 @@ LL | drop(slice1.cmp(slice2)); | ^^^^^^^^^^^^^^^^^^ Uninitialized memory occurred at ALLOC[0x4..0x8], in this allocation: -ALLOC (C heap, size: 16, align: 16) { +ALLOC (Rust heap, size: 16, align: 8) { ╾42[ALLOC] (1 ptr byte)╼ 12 13 ╾43[ALLOC] (1 ptr byte)╼ __ __ __ __ __ __ __ __ __ __ __ __ │ ━..━░░░░░░░░░░░░ } ALLOC (global (static or const), size: 1, align: 1) {