Skip to content

Commit b30b535

Browse files
committed
Auto merge of #115408 - RalfJung:miri, r=RalfJung
update Miri r? `@ghost`
2 parents 784916c + 873a7a3 commit b30b535

15 files changed

+286
-101
lines changed

src/tools/miri/ci.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ case $HOST_TARGET in
107107
MIRI_TEST_TARGET=i686-unknown-linux-gnu run_tests
108108
MIRI_TEST_TARGET=aarch64-unknown-linux-gnu run_tests
109109
MIRI_TEST_TARGET=aarch64-apple-darwin run_tests
110-
MIRI_TEST_TARGET=i686-pc-windows-msvc run_tests
110+
MIRI_TEST_TARGET=i686-pc-windows-gnu run_tests
111111
MIRI_TEST_TARGET=x86_64-unknown-freebsd run_tests_minimal hello integer vec panic/panic concurrency/simple atomic data_race env/var
112112
MIRI_TEST_TARGET=aarch64-linux-android run_tests_minimal hello integer vec panic/panic
113113
MIRI_TEST_TARGET=wasm32-wasi run_tests_minimal no_std integer strings

src/tools/miri/rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
c40cfcf0494ff7506e753e750adb00eeea839f9c
1+
dca2d1ff00bf96d244b1bb9a2117a92ec50ac71d

src/tools/miri/src/diagnostics.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -272,26 +272,24 @@ pub fn report_error<'tcx, 'mir>(
272272
} else {
273273
let title = match e.kind() {
274274
UndefinedBehavior(UndefinedBehaviorInfo::ValidationError(validation_err))
275-
if matches!(validation_err.kind, ValidationErrorKind::PointerAsInt { .. } | ValidationErrorKind::PartialPointer) =>
275+
if matches!(
276+
validation_err.kind,
277+
ValidationErrorKind::PointerAsInt { .. } | ValidationErrorKind::PartialPointer
278+
) =>
276279
{
277280
ecx.handle_ice(); // print interpreter backtrace
278281
bug!("This validation error should be impossible in Miri: {}", ecx.format_error(e));
279282
}
280-
UndefinedBehavior(_) =>
281-
"Undefined Behavior",
282-
ResourceExhaustion(_) =>
283-
"resource exhaustion",
283+
UndefinedBehavior(_) => "Undefined Behavior",
284+
ResourceExhaustion(_) => "resource exhaustion",
284285
Unsupported(
285286
// We list only the ones that can actually happen.
286-
UnsupportedOpInfo::Unsupported(_) | UnsupportedOpInfo::UnsizedLocal
287-
) =>
288-
"unsupported operation",
287+
UnsupportedOpInfo::Unsupported(_) | UnsupportedOpInfo::UnsizedLocal,
288+
) => "unsupported operation",
289289
InvalidProgram(
290290
// We list only the ones that can actually happen.
291-
InvalidProgramInfo::AlreadyReported(_) |
292-
InvalidProgramInfo::Layout(..)
293-
) =>
294-
"post-monomorphization error",
291+
InvalidProgramInfo::AlreadyReported(_) | InvalidProgramInfo::Layout(..),
292+
) => "post-monomorphization error",
295293
_ => {
296294
ecx.handle_ice(); // print interpreter backtrace
297295
bug!("This error should be impossible in Miri: {}", ecx.format_error(e));
@@ -346,7 +344,8 @@ pub fn report_error<'tcx, 'mir>(
346344
extra,
347345
"Uninitialized memory occurred at {alloc_id:?}{range:?}, in this allocation:",
348346
range = access.bad,
349-
).unwrap();
347+
)
348+
.unwrap();
350349
writeln!(extra, "{:?}", ecx.dump_alloc(*alloc_id)).unwrap();
351350
}
352351
_ => {}

src/tools/miri/src/machine.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,10 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
975975
ecx.start_panic_nounwind(msg)
976976
}
977977

978-
fn unwind_terminate(ecx: &mut InterpCx<'mir, 'tcx, Self>, reason: mir::UnwindTerminateReason) -> InterpResult<'tcx> {
978+
fn unwind_terminate(
979+
ecx: &mut InterpCx<'mir, 'tcx, Self>,
980+
reason: mir::UnwindTerminateReason,
981+
) -> InterpResult<'tcx> {
979982
// Call the lang item.
980983
let panic = ecx.tcx.lang_items().get(reason.lang_item()).unwrap();
981984
let panic = ty::Instance::mono(ecx.tcx.tcx, panic);
@@ -1410,17 +1413,14 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
14101413
ecx: &mut InterpCx<'mir, 'tcx, Self>,
14111414
frame: usize,
14121415
local: mir::Local,
1413-
mplace: &MPlaceTy<'tcx, Provenance>
1416+
mplace: &MPlaceTy<'tcx, Provenance>,
14141417
) -> InterpResult<'tcx> {
14151418
let Some(Provenance::Concrete { alloc_id, .. }) = mplace.ptr.provenance else {
14161419
panic!("after_local_allocated should only be called on fresh allocations");
14171420
};
14181421
let local_decl = &ecx.active_thread_stack()[frame].body.local_decls[local];
14191422
let span = local_decl.source_info.span;
1420-
ecx.machine
1421-
.allocation_spans
1422-
.borrow_mut()
1423-
.insert(alloc_id, (span, None));
1423+
ecx.machine.allocation_spans.borrow_mut().insert(alloc_id, (span, None));
14241424
Ok(())
14251425
}
14261426
}

src/tools/miri/tests/fail/function_calls/exported_symbol_bad_unwind2.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//@revisions: extern_block definition both
22
//@normalize-stderr-test: "unsafe \{ libc::abort\(\) \}|crate::intrinsics::abort\(\);" -> "ABORT();"
33
//@normalize-stderr-test: "\| +\^+" -> "| ^"
4-
//@normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> "$1"
5-
//@normalize-stderr-test: "\n at [^\n]+" -> "$1"
4+
//@normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> ""
5+
//@normalize-stderr-test: "\n +at [^\n]+" -> ""
66
//@[definition,both]error-in-other-file: aborted execution
77
#![feature(rustc_attrs, c_unwind)]
88

src/tools/miri/tests/fail/intrinsics/uninit_uninhabited_type.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@normalize-stderr-test: "unsafe \{ libc::abort\(\) \}|crate::intrinsics::abort\(\);" -> "ABORT();"
22
//@normalize-stderr-test: "\| +\^+" -> "| ^"
3-
//@normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> "$1"
4-
//@normalize-stderr-test: "\n at [^\n]+" -> "$1"
3+
//@normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> ""
4+
//@normalize-stderr-test: "\n +at [^\n]+" -> ""
55
//@error-in-other-file: aborted execution
66
#![feature(never_type)]
77

src/tools/miri/tests/fail/intrinsics/zero_fn_ptr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@normalize-stderr-test: "unsafe \{ libc::abort\(\) \}|crate::intrinsics::abort\(\);" -> "ABORT();"
22
//@normalize-stderr-test: "\| +\^+" -> "| ^"
3-
//@normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> "$1"
4-
//@normalize-stderr-test: "\n at [^\n]+" -> "$1"
3+
//@normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> ""
4+
//@normalize-stderr-test: "\n +at [^\n]+" -> ""
55
//@error-in-other-file: aborted execution
66

77
#[allow(deprecated, invalid_value)]

src/tools/miri/tests/fail/panic/double_panic.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@normalize-stderr-test: "unsafe \{ libc::abort\(\) \}|crate::intrinsics::abort\(\);" -> "ABORT();"
22
//@normalize-stderr-test: "\| +\^+" -> "| ^"
3-
//@normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> "$1"
4-
//@normalize-stderr-test: "\n at [^\n]+" -> "$1"
3+
//@normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> ""
4+
//@normalize-stderr-test: "\n +at [^\n]+" -> ""
55
//@error-in-other-file: aborted execution
66

77
struct Foo;

src/tools/miri/tests/fail/terminate-terminator.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//@compile-flags: -Zmir-opt-level=3 -Zinline-mir-hint-threshold=1000
22
//@normalize-stderr-test: "unsafe \{ libc::abort\(\) \}|crate::intrinsics::abort\(\);" -> "ABORT();"
33
//@normalize-stderr-test: "\| +\^+" -> "| ^"
4-
//@normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> "$1"
5-
//@normalize-stderr-test: "\n at [^\n]+" -> "$1"
4+
//@normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> ""
5+
//@normalize-stderr-test: "\n +at [^\n]+" -> ""
66
//@error-in-other-file: aborted execution
77
// Enable MIR inlining to ensure that `TerminatorKind::UnwindTerminate` is generated
88
// instead of just `UnwindAction::Terminate`.

src/tools/miri/tests/fail/unwind-action-terminate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//@error-in-other-file: aborted execution
22
//@normalize-stderr-test: "unsafe \{ libc::abort\(\) \}|crate::intrinsics::abort\(\);" -> "ABORT();"
33
//@normalize-stderr-test: "\| +\^+" -> "| ^"
4-
//@normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> "$1"
5-
//@normalize-stderr-test: "\n at [^\n]+" -> "$1"
4+
//@normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> ""
5+
//@normalize-stderr-test: "\n +at [^\n]+" -> ""
66
#![feature(c_unwind)]
77

88
extern "C" fn panic_abort() {
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,91 @@
11
#![feature(portable_simd)]
2-
use std::num;
32
use std::mem;
3+
use std::num;
44
use std::simd;
55

6-
fn test_abi_compat<T, U>(t: T, u: U) {
7-
fn id<T>(x: T) -> T { x }
8-
6+
#[derive(Copy, Clone)]
7+
struct Zst;
8+
9+
fn test_abi_compat<T: Copy, U: Copy>(t: T, u: U) {
10+
fn id<T>(x: T) -> T {
11+
x
12+
}
13+
extern "C" fn id_c<T>(x: T) -> T {
14+
x
15+
}
16+
917
// This checks ABI compatibility both for arguments and return values,
1018
// in both directions.
1119
let f: fn(T) -> T = id;
1220
let f: fn(U) -> U = unsafe { std::mem::transmute(f) };
13-
drop(f(u));
14-
21+
let _val = f(u);
1522
let f: fn(U) -> U = id;
1623
let f: fn(T) -> T = unsafe { std::mem::transmute(f) };
17-
drop(f(t));
24+
let _val = f(t);
25+
26+
// And then we do the same for `extern "C"`.
27+
let f: extern "C" fn(T) -> T = id_c;
28+
let f: extern "C" fn(U) -> U = unsafe { std::mem::transmute(f) };
29+
let _val = f(u);
30+
let f: extern "C" fn(U) -> U = id_c;
31+
let f: extern "C" fn(T) -> T = unsafe { std::mem::transmute(f) };
32+
let _val = f(t);
1833
}
1934

2035
/// Ensure that `T` is compatible with various repr(transparent) wrappers around `T`.
2136
fn test_abi_newtype<T: Copy>(t: T) {
2237
#[repr(transparent)]
38+
#[derive(Copy, Clone)]
2339
struct Wrapper1<T>(T);
2440
#[repr(transparent)]
41+
#[derive(Copy, Clone)]
2542
struct Wrapper2<T>(T, ());
2643
#[repr(transparent)]
44+
#[derive(Copy, Clone)]
2745
struct Wrapper2a<T>((), T);
2846
#[repr(transparent)]
29-
struct Wrapper3<T>(T, [u8; 0]);
47+
#[derive(Copy, Clone)]
48+
struct Wrapper3<T>(Zst, T, [u8; 0]);
3049

3150
test_abi_compat(t, Wrapper1(t));
3251
test_abi_compat(t, Wrapper2(t, ()));
3352
test_abi_compat(t, Wrapper2a((), t));
34-
test_abi_compat(t, Wrapper3(t, []));
53+
test_abi_compat(t, Wrapper3(Zst, t, []));
54+
test_abi_compat(t, mem::MaybeUninit::new(t)); // MaybeUninit is `repr(transparent)`
3555
}
3656

3757
fn main() {
58+
// Here we check:
59+
// - unsigned vs signed integer is allowed
60+
// - u32/i32 vs char is allowed
61+
// - u32 vs NonZeroU32/Option<NonZeroU32> is allowed
62+
// - reference vs raw pointer is allowed
63+
// - references to things of the same size and alignment are allowed
64+
// These are very basic tests that should work on all ABIs. However it is not clear that any of
65+
// these would be stably guaranteed. Code that relies on this is equivalent to code that relies
66+
// on the layout of `repr(Rust)` types. They are also fragile: the same mismatches in the fields
67+
// of a struct (even with `repr(C)`) will not always be accepted by Miri.
68+
test_abi_compat(0u32, 0i32);
69+
test_abi_compat(simd::u32x8::splat(1), simd::i32x8::splat(1));
3870
test_abi_compat(0u32, 'x');
39-
test_abi_compat(&0u32, &([true; 4], [0u32; 0]));
40-
test_abi_compat(0u32, mem::MaybeUninit::new(0u32));
71+
test_abi_compat(0i32, 'x');
4172
test_abi_compat(42u32, num::NonZeroU32::new(1).unwrap());
4273
test_abi_compat(0u32, Some(num::NonZeroU32::new(1).unwrap()));
43-
test_abi_compat(0u32, 0i32);
44-
test_abi_compat(simd::u32x8::splat(1), simd::i32x8::splat(1));
74+
test_abi_compat(&0u32, &0u32 as *const u32);
75+
test_abi_compat(&0u32, &([true; 4], [0u32; 0]));
4576
// Note that `bool` and `u8` are *not* compatible, at least on x86-64!
4677
// One of them has `arg_ext: Zext`, the other does not.
4778

79+
// These must work for *any* type, since we guarantee that `repr(transparent)` is ABI-compatible
80+
// with the wrapped field.
81+
test_abi_newtype(());
82+
// FIXME: this still fails! test_abi_newtype(Zst);
4883
test_abi_newtype(0u32);
4984
test_abi_newtype(0f32);
5085
test_abi_newtype((0u32, 1u32, 2u32));
51-
test_abi_newtype([0u32, 1u32, 2u32]);
52-
test_abi_newtype([0i32; 0]);
86+
// FIXME: skipping the array tests on mips64 due to https://github.com/rust-lang/rust/issues/115404
87+
if !cfg!(target_arch = "mips64") {
88+
test_abi_newtype([0u32, 1u32, 2u32]);
89+
test_abi_newtype([0i32; 0]);
90+
}
5391
}

src/tools/miri/tests/pass/panic/catch_panic.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// We test the `align_offset` panic below, make sure we test the interpreter impl and not the "real" one.
2-
//@compile-flags: -Zmiri-symbolic-alignment-check -Zmiri-permissive-provenance
2+
//@compile-flags: -Zmiri-symbolic-alignment-check
33
#![feature(never_type)]
44
#![allow(unconditional_panic, non_fmt_panics)]
55

@@ -48,14 +48,16 @@ fn main() {
4848
}));
4949

5050
// Std panics
51-
test(None, |_old_val| std::panic!("Hello from panic: std"));
52-
test(None, |old_val| std::panic::panic_any(format!("Hello from panic: {:?}", old_val)));
53-
test(None, |old_val| std::panic!("Hello from panic: {:?}", old_val));
51+
test(None, |_old_val| std::panic!("Hello from std::panic"));
52+
test(None, |old_val| std::panic!("Hello from std::panic: {:?}", old_val));
53+
test(None, |old_val| {
54+
std::panic::panic_any(format!("Hello from std::panic_any: {:?}", old_val))
55+
});
5456
test(None, |_old_val| std::panic::panic_any(1337));
5557

5658
// Core panics
57-
test(None, |_old_val| core::panic!("Hello from panic: core"));
58-
test(None, |old_val| core::panic!("Hello from panic: {:?}", old_val));
59+
test(None, |_old_val| core::panic!("Hello from core::panic"));
60+
test(None, |old_val| core::panic!("Hello from core::panic: {:?}", old_val));
5961

6062
// Built-in panics; also make sure the message is right.
6163
test(Some("index out of bounds: the len is 3 but the index is 4"), |_old_val| {
@@ -68,7 +70,7 @@ fn main() {
6870
});
6971

7072
test(Some("align_offset: align is not a power-of-two"), |_old_val| {
71-
let _ = (0usize as *const u8).align_offset(3);
73+
let _ = std::ptr::null::<u8>().align_offset(3);
7274
loop {}
7375
});
7476

src/tools/miri/tests/pass/panic/catch_panic.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
thread 'main' panicked at $DIR/catch_panic.rs:LL:CC:
2-
Hello from panic: std
2+
Hello from std::panic
33
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
4-
Caught panic message (&str): Hello from panic: std
4+
Caught panic message (&str): Hello from std::panic
55
thread 'main' panicked at $DIR/catch_panic.rs:LL:CC:
6-
Hello from panic: 1
7-
Caught panic message (String): Hello from panic: 1
6+
Hello from std::panic: 1
7+
Caught panic message (String): Hello from std::panic: 1
88
thread 'main' panicked at $DIR/catch_panic.rs:LL:CC:
9-
Hello from panic: 2
10-
Caught panic message (String): Hello from panic: 2
9+
Hello from std::panic_any: 2
10+
Caught panic message (String): Hello from std::panic_any: 2
1111
thread 'main' panicked at $DIR/catch_panic.rs:LL:CC:
1212
Box<dyn Any>
1313
Failed to get caught panic message.
1414
thread 'main' panicked at $DIR/catch_panic.rs:LL:CC:
15-
Hello from panic: core
16-
Caught panic message (&str): Hello from panic: core
15+
Hello from core::panic
16+
Caught panic message (&str): Hello from core::panic
1717
thread 'main' panicked at $DIR/catch_panic.rs:LL:CC:
18-
Hello from panic: 5
19-
Caught panic message (String): Hello from panic: 5
18+
Hello from core::panic: 5
19+
Caught panic message (String): Hello from core::panic: 5
2020
thread 'main' panicked at $DIR/catch_panic.rs:LL:CC:
2121
index out of bounds: the len is 3 but the index is 4
2222
Caught panic message (String): index out of bounds: the len is 3 but the index is 4

src/tools/miri/tests/pass/panic/nested_panic_caught.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@normalize-stderr-test: "\| +\^+" -> "| ^"
2-
//@normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> "$1"
3-
//@normalize-stderr-test: "\n at [^\n]+" -> "$1"
2+
//@normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> ""
3+
//@normalize-stderr-test: "\n +at [^\n]+" -> ""
44

55
// Checks that nested panics work correctly.
66

0 commit comments

Comments
 (0)