Skip to content

Commit 08bddfb

Browse files
committed
Bless miri tests
1 parent 1dd2f56 commit 08bddfb

29 files changed

+336
-159
lines changed

library/alloc/src/alloc.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ use core::ptr::{self, NonNull};
1212

1313
extern "Rust" {
1414
// These are the magic symbols to call the global allocator. rustc generates
15-
// them to call `__rg_alloc` etc. if there is a `#[global_allocator]` attribute
16-
// (the code expanding that attribute macro generates those functions), or to call
15+
// them to call `GLOBAL.alloc` etc. if there is a `#[global_allocator]` attribute
16+
// (the code expanding that attribute macro generates those functions), or if not
1717
// the default implementations in std (weak symbols in `library/std/src/alloc.rs`)
18-
// otherwise.
19-
// The rustc fork of LLVM 14 and earlier also special-cases these function names to be able to optimize them
20-
// like `malloc`, `realloc`, and `free`, respectively.
18+
// is used otherwise.
19+
// The rustc fork of LLVM 14 and earlier also special-cases these function names to
20+
// be able to optimize them like `malloc`, `realloc`, and `free`, respectively.
2121
#[rustc_allocator]
2222
#[rustc_nounwind]
2323
fn __rust_alloc(size: usize, align: usize) -> *mut u8;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ LL | ABORT();
99
= note: inside `std::sys::pal::PLATFORM::abort_internal` at RUSTLIB/std/src/sys/pal/PLATFORM/mod.rs:LL:CC
1010
= note: inside `std::process::abort` at RUSTLIB/std/src/process.rs:LL:CC
1111
= note: inside `std::alloc::rust_oom` at RUSTLIB/std/src/alloc.rs:LL:CC
12-
= note: inside `std::alloc::_::__rg_oom` at RUSTLIB/std/src/alloc.rs:LL:CC
12+
= note: inside `std::alloc::_::__rust_alloc_error_handler` at RUSTLIB/std/src/alloc.rs:LL:CC
1313
= note: inside `std::alloc::handle_alloc_error::rt_error` at RUSTLIB/alloc/src/alloc.rs:LL:CC
1414
= note: inside `std::alloc::handle_alloc_error` at RUSTLIB/alloc/src/alloc.rs:LL:CC
1515
note: inside `main`

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | core::intrinsics::abort();
77
|
88
= note: BACKTRACE:
99
= note: inside `alloc_error_handler` at tests/fail/alloc/alloc_error_handler_custom.rs:LL:CC
10-
note: inside `_::__rg_oom`
10+
note: inside `_::__rust_alloc_error_handler`
1111
--> tests/fail/alloc/alloc_error_handler_custom.rs:LL:CC
1212
|
1313
LL | #[alloc_error_handler]

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ LL | core::intrinsics::abort();
99
|
1010
= note: BACKTRACE:
1111
= note: inside `panic_handler` at tests/fail/alloc/alloc_error_handler_no_std.rs:LL:CC
12-
= note: inside `alloc::alloc::__alloc_error_handler::__rdl_oom` at RUSTLIB/alloc/src/alloc.rs:LL:CC
12+
= note: inside `alloc::alloc::__alloc_error_handler::__rust_alloc_error_handler` at RUSTLIB/alloc/src/alloc.rs:LL:CC
1313
= note: inside `alloc::alloc::handle_alloc_error::rt_error` at RUSTLIB/alloc/src/alloc.rs:LL:CC
1414
= note: inside `alloc::alloc::handle_alloc_error` at RUSTLIB/alloc/src/alloc.rs:LL:CC
1515
note: inside `start`

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

-15
This file was deleted.

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

-15
This file was deleted.

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

+10-4
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-
--> tests/fail/alloc/deallocate-twice.rs:LL:CC
2+
--> RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC
33
|
4-
LL | dealloc(x, Layout::from_size_align_unchecked(1, 1));
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: ALLOC has been freed, so this pointer is dangling
4+
LL | unsafe { libc::free(ptr as *mut libc::c_void) }
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,7 +17,13 @@ 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 `main` at tests/fail/alloc/deallocate-twice.rs:LL:CC
20+
= note: inside `std::sys::alloc::unix::<impl std::alloc::GlobalAlloc for std::alloc::System>::dealloc` at RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC
21+
= note: inside `std::alloc::__default_lib_allocator::__rust_dealloc` at RUSTLIB/std/src/alloc.rs:LL:CC
22+
note: inside `main`
23+
--> tests/fail/alloc/deallocate-twice.rs:LL:CC
24+
|
25+
LL | dealloc(x, Layout::from_size_align_unchecked(1, 1));
26+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2127

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

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

-21
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1-
error: Undefined Behavior: incorrect layout on deallocation: ALLOC has size 1 and alignment ALIGN, but gave size 2 and alignment ALIGN
2-
--> tests/fail/alloc/reallocate-bad-size.rs:LL:CC
1+
error: memory leaked: ALLOC (C heap, size: 1, align: 1), allocated here:
2+
--> RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC
33
|
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
4+
LL | unsafe { libc::realloc(ptr as *mut libc::c_void, new_size) as *mut u8 }
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
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
97
= note: BACKTRACE:
10-
= note: inside `main` at tests/fail/alloc/reallocate-bad-size.rs:LL:CC
8+
= note: inside `std::sys::alloc::unix::<impl std::alloc::GlobalAlloc for std::alloc::System>::realloc` at RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC
9+
= note: inside `std::alloc::__default_lib_allocator::__rust_realloc` at RUSTLIB/std/src/alloc.rs:LL:CC
10+
note: inside `main`
11+
--> tests/fail/alloc/reallocate-bad-size.rs:LL:CC
12+
|
13+
LL | ... let _y = realloc(x, Layout::from_size_align_unchecked(2, 1), 1);
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1115

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

18+
note: set `MIRIFLAGS=-Zmiri-ignore-leaks` to disable this check
19+
1420
error: aborting due to 1 previous error
1521

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

+10-4
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-
--> tests/fail/alloc/reallocate-dangling.rs:LL:CC
2+
--> RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC
33
|
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
4+
LL | unsafe { libc::realloc(ptr as *mut libc::c_void, new_size) as *mut u8 }
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,7 +17,13 @@ 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 `main` at tests/fail/alloc/reallocate-dangling.rs:LL:CC
20+
= note: inside `std::sys::alloc::unix::<impl std::alloc::GlobalAlloc for std::alloc::System>::realloc` at RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC
21+
= note: inside `std::alloc::__default_lib_allocator::__rust_realloc` at RUSTLIB/std/src/alloc.rs:LL:CC
22+
note: inside `main`
23+
--> tests/fail/alloc/reallocate-dangling.rs:LL:CC
24+
|
25+
LL | let _z = realloc(x, Layout::from_size_align_unchecked(1, 1), 1);
26+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2127

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

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
error: Undefined Behavior: deallocating ALLOC, which is stack variable memory, using Rust heap deallocation operation
2-
--> RUSTLIB/alloc/src/boxed.rs:LL:CC
1+
error: Undefined Behavior: deallocating ALLOC, which is stack variable memory, using C heap deallocation operation
2+
--> RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC
33
|
4-
LL | self.1.deallocate(From::from(ptr.cast()), layout);
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ deallocating ALLOC, which is stack variable memory, using Rust heap deallocation operation
4+
LL | unsafe { libc::free(ptr as *mut libc::c_void) }
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ deallocating ALLOC, which is stack variable memory, using C 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::sys::alloc::unix::<impl std::alloc::GlobalAlloc for std::alloc::System>::dealloc` at RUSTLIB/std/src/sys/alloc/unix.rs:LL:CC
11+
= note: inside `std::alloc::__default_lib_allocator::__rust_dealloc` at RUSTLIB/std/src/alloc.rs:LL:CC
1012
= note: inside `<std::boxed::Box<i32> as std::ops::Drop>::drop` at RUSTLIB/alloc/src/boxed.rs:LL:CC
1113
= 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
1214
= note: inside `std::mem::drop::<std::boxed::Box<i32>>` at RUSTLIB/core/src/mem/mod.rs:LL:CC

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

+23-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
1-
error: Undefined Behavior: creating an allocation larger than half the address space
2-
--> tests/fail/alloc/too_large.rs:LL:CC
1+
thread 'main' panicked at RUSTLIB/core/src/panicking.rs:LL:CC:
2+
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
3+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
4+
note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect
5+
thread caused non-unwinding panic. aborting.
6+
error: abnormal termination: the program aborted execution
7+
--> RUSTLIB/std/src/sys/pal/PLATFORM/mod.rs:LL:CC
38
|
4-
LL | __rust_alloc(bytes, 1);
5-
| ^^^^^^^^^^^^^^^^^^^^^^ creating an allocation larger than half the address space
9+
LL | unsafe { libc::abort() }
10+
| ^^^^^^^^^^^^^ the program aborted execution
611
|
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
912
= note: BACKTRACE:
10-
= note: inside `main` at tests/fail/alloc/too_large.rs:LL:CC
13+
= note: inside `std::sys::pal::PLATFORM::abort_internal` at RUSTLIB/std/src/sys/pal/PLATFORM/mod.rs:LL:CC
14+
= note: inside `std::panicking::rust_panic_with_hook` at RUSTLIB/std/src/panicking.rs:LL:CC
15+
= note: inside closure at RUSTLIB/std/src/panicking.rs:LL:CC
16+
= 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
17+
= note: inside `std::panicking::begin_panic_handler` at RUSTLIB/std/src/panicking.rs:LL:CC
18+
= note: inside `core::panicking::panic_nounwind` at RUSTLIB/core/src/panicking.rs:LL:CC
19+
= note: inside `std::alloc::Layout::from_size_align_unchecked::precondition_check` at RUSTLIB/core/src/ub_checks.rs:LL:CC
20+
= note: inside `std::alloc::Layout::from_size_align_unchecked` at RUSTLIB/core/src/ub_checks.rs:LL:CC
21+
= note: inside `std::alloc::__default_lib_allocator::__rust_alloc` at RUSTLIB/std/src/alloc.rs:LL:CC
22+
note: inside `main`
23+
--> tests/fail/alloc/too_large.rs:LL:CC
24+
|
25+
LL | __rust_alloc(bytes, 1);
26+
| ^^^^^^^^^^^^^^^^^^^^^^
1127

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

0 commit comments

Comments
 (0)