Skip to content

Commit

Permalink
Auto merge of #115408 - RalfJung:miri, r=RalfJung
Browse files Browse the repository at this point in the history
update Miri

r? `@ghost`
  • Loading branch information
bors committed Aug 31, 2023
2 parents 784916c + 873a7a3 commit b30b535
Show file tree
Hide file tree
Showing 15 changed files with 286 additions and 101 deletions.
2 changes: 1 addition & 1 deletion src/tools/miri/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ case $HOST_TARGET in
MIRI_TEST_TARGET=i686-unknown-linux-gnu run_tests
MIRI_TEST_TARGET=aarch64-unknown-linux-gnu run_tests
MIRI_TEST_TARGET=aarch64-apple-darwin run_tests
MIRI_TEST_TARGET=i686-pc-windows-msvc run_tests
MIRI_TEST_TARGET=i686-pc-windows-gnu run_tests
MIRI_TEST_TARGET=x86_64-unknown-freebsd run_tests_minimal hello integer vec panic/panic concurrency/simple atomic data_race env/var
MIRI_TEST_TARGET=aarch64-linux-android run_tests_minimal hello integer vec panic/panic
MIRI_TEST_TARGET=wasm32-wasi run_tests_minimal no_std integer strings
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
c40cfcf0494ff7506e753e750adb00eeea839f9c
dca2d1ff00bf96d244b1bb9a2117a92ec50ac71d
25 changes: 12 additions & 13 deletions src/tools/miri/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,26 +272,24 @@ pub fn report_error<'tcx, 'mir>(
} else {
let title = match e.kind() {
UndefinedBehavior(UndefinedBehaviorInfo::ValidationError(validation_err))
if matches!(validation_err.kind, ValidationErrorKind::PointerAsInt { .. } | ValidationErrorKind::PartialPointer) =>
if matches!(
validation_err.kind,
ValidationErrorKind::PointerAsInt { .. } | ValidationErrorKind::PartialPointer
) =>
{
ecx.handle_ice(); // print interpreter backtrace
bug!("This validation error should be impossible in Miri: {}", ecx.format_error(e));
}
UndefinedBehavior(_) =>
"Undefined Behavior",
ResourceExhaustion(_) =>
"resource exhaustion",
UndefinedBehavior(_) => "Undefined Behavior",
ResourceExhaustion(_) => "resource exhaustion",
Unsupported(
// We list only the ones that can actually happen.
UnsupportedOpInfo::Unsupported(_) | UnsupportedOpInfo::UnsizedLocal
) =>
"unsupported operation",
UnsupportedOpInfo::Unsupported(_) | UnsupportedOpInfo::UnsizedLocal,
) => "unsupported operation",
InvalidProgram(
// We list only the ones that can actually happen.
InvalidProgramInfo::AlreadyReported(_) |
InvalidProgramInfo::Layout(..)
) =>
"post-monomorphization error",
InvalidProgramInfo::AlreadyReported(_) | InvalidProgramInfo::Layout(..),
) => "post-monomorphization error",
_ => {
ecx.handle_ice(); // print interpreter backtrace
bug!("This error should be impossible in Miri: {}", ecx.format_error(e));
Expand Down Expand Up @@ -346,7 +344,8 @@ pub fn report_error<'tcx, 'mir>(
extra,
"Uninitialized memory occurred at {alloc_id:?}{range:?}, in this allocation:",
range = access.bad,
).unwrap();
)
.unwrap();
writeln!(extra, "{:?}", ecx.dump_alloc(*alloc_id)).unwrap();
}
_ => {}
Expand Down
12 changes: 6 additions & 6 deletions src/tools/miri/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,10 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
ecx.start_panic_nounwind(msg)
}

fn unwind_terminate(ecx: &mut InterpCx<'mir, 'tcx, Self>, reason: mir::UnwindTerminateReason) -> InterpResult<'tcx> {
fn unwind_terminate(
ecx: &mut InterpCx<'mir, 'tcx, Self>,
reason: mir::UnwindTerminateReason,
) -> InterpResult<'tcx> {
// Call the lang item.
let panic = ecx.tcx.lang_items().get(reason.lang_item()).unwrap();
let panic = ty::Instance::mono(ecx.tcx.tcx, panic);
Expand Down Expand Up @@ -1410,17 +1413,14 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
ecx: &mut InterpCx<'mir, 'tcx, Self>,
frame: usize,
local: mir::Local,
mplace: &MPlaceTy<'tcx, Provenance>
mplace: &MPlaceTy<'tcx, Provenance>,
) -> InterpResult<'tcx> {
let Some(Provenance::Concrete { alloc_id, .. }) = mplace.ptr.provenance else {
panic!("after_local_allocated should only be called on fresh allocations");
};
let local_decl = &ecx.active_thread_stack()[frame].body.local_decls[local];
let span = local_decl.source_info.span;
ecx.machine
.allocation_spans
.borrow_mut()
.insert(alloc_id, (span, None));
ecx.machine.allocation_spans.borrow_mut().insert(alloc_id, (span, None));
Ok(())
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//@revisions: extern_block definition both
//@normalize-stderr-test: "unsafe \{ libc::abort\(\) \}|crate::intrinsics::abort\(\);" -> "ABORT();"
//@normalize-stderr-test: "\| +\^+" -> "| ^"
//@normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> "$1"
//@normalize-stderr-test: "\n at [^\n]+" -> "$1"
//@normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> ""
//@normalize-stderr-test: "\n +at [^\n]+" -> ""
//@[definition,both]error-in-other-file: aborted execution
#![feature(rustc_attrs, c_unwind)]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//@normalize-stderr-test: "unsafe \{ libc::abort\(\) \}|crate::intrinsics::abort\(\);" -> "ABORT();"
//@normalize-stderr-test: "\| +\^+" -> "| ^"
//@normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> "$1"
//@normalize-stderr-test: "\n at [^\n]+" -> "$1"
//@normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> ""
//@normalize-stderr-test: "\n +at [^\n]+" -> ""
//@error-in-other-file: aborted execution
#![feature(never_type)]

Expand Down
4 changes: 2 additions & 2 deletions src/tools/miri/tests/fail/intrinsics/zero_fn_ptr.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//@normalize-stderr-test: "unsafe \{ libc::abort\(\) \}|crate::intrinsics::abort\(\);" -> "ABORT();"
//@normalize-stderr-test: "\| +\^+" -> "| ^"
//@normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> "$1"
//@normalize-stderr-test: "\n at [^\n]+" -> "$1"
//@normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> ""
//@normalize-stderr-test: "\n +at [^\n]+" -> ""
//@error-in-other-file: aborted execution

#[allow(deprecated, invalid_value)]
Expand Down
4 changes: 2 additions & 2 deletions src/tools/miri/tests/fail/panic/double_panic.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//@normalize-stderr-test: "unsafe \{ libc::abort\(\) \}|crate::intrinsics::abort\(\);" -> "ABORT();"
//@normalize-stderr-test: "\| +\^+" -> "| ^"
//@normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> "$1"
//@normalize-stderr-test: "\n at [^\n]+" -> "$1"
//@normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> ""
//@normalize-stderr-test: "\n +at [^\n]+" -> ""
//@error-in-other-file: aborted execution

struct Foo;
Expand Down
4 changes: 2 additions & 2 deletions src/tools/miri/tests/fail/terminate-terminator.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//@compile-flags: -Zmir-opt-level=3 -Zinline-mir-hint-threshold=1000
//@normalize-stderr-test: "unsafe \{ libc::abort\(\) \}|crate::intrinsics::abort\(\);" -> "ABORT();"
//@normalize-stderr-test: "\| +\^+" -> "| ^"
//@normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> "$1"
//@normalize-stderr-test: "\n at [^\n]+" -> "$1"
//@normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> ""
//@normalize-stderr-test: "\n +at [^\n]+" -> ""
//@error-in-other-file: aborted execution
// Enable MIR inlining to ensure that `TerminatorKind::UnwindTerminate` is generated
// instead of just `UnwindAction::Terminate`.
Expand Down
4 changes: 2 additions & 2 deletions src/tools/miri/tests/fail/unwind-action-terminate.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//@error-in-other-file: aborted execution
//@normalize-stderr-test: "unsafe \{ libc::abort\(\) \}|crate::intrinsics::abort\(\);" -> "ABORT();"
//@normalize-stderr-test: "\| +\^+" -> "| ^"
//@normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> "$1"
//@normalize-stderr-test: "\n at [^\n]+" -> "$1"
//@normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> ""
//@normalize-stderr-test: "\n +at [^\n]+" -> ""
#![feature(c_unwind)]

extern "C" fn panic_abort() {
Expand Down
68 changes: 53 additions & 15 deletions src/tools/miri/tests/pass/function_calls/abi_compat.rs
Original file line number Diff line number Diff line change
@@ -1,53 +1,91 @@
#![feature(portable_simd)]
use std::num;
use std::mem;
use std::num;
use std::simd;

fn test_abi_compat<T, U>(t: T, u: U) {
fn id<T>(x: T) -> T { x }

#[derive(Copy, Clone)]
struct Zst;

fn test_abi_compat<T: Copy, U: Copy>(t: T, u: U) {
fn id<T>(x: T) -> T {
x
}
extern "C" fn id_c<T>(x: T) -> T {
x
}

// This checks ABI compatibility both for arguments and return values,
// in both directions.
let f: fn(T) -> T = id;
let f: fn(U) -> U = unsafe { std::mem::transmute(f) };
drop(f(u));

let _val = f(u);
let f: fn(U) -> U = id;
let f: fn(T) -> T = unsafe { std::mem::transmute(f) };
drop(f(t));
let _val = f(t);

// And then we do the same for `extern "C"`.
let f: extern "C" fn(T) -> T = id_c;
let f: extern "C" fn(U) -> U = unsafe { std::mem::transmute(f) };
let _val = f(u);
let f: extern "C" fn(U) -> U = id_c;
let f: extern "C" fn(T) -> T = unsafe { std::mem::transmute(f) };
let _val = f(t);
}

/// Ensure that `T` is compatible with various repr(transparent) wrappers around `T`.
fn test_abi_newtype<T: Copy>(t: T) {
#[repr(transparent)]
#[derive(Copy, Clone)]
struct Wrapper1<T>(T);
#[repr(transparent)]
#[derive(Copy, Clone)]
struct Wrapper2<T>(T, ());
#[repr(transparent)]
#[derive(Copy, Clone)]
struct Wrapper2a<T>((), T);
#[repr(transparent)]
struct Wrapper3<T>(T, [u8; 0]);
#[derive(Copy, Clone)]
struct Wrapper3<T>(Zst, T, [u8; 0]);

test_abi_compat(t, Wrapper1(t));
test_abi_compat(t, Wrapper2(t, ()));
test_abi_compat(t, Wrapper2a((), t));
test_abi_compat(t, Wrapper3(t, []));
test_abi_compat(t, Wrapper3(Zst, t, []));
test_abi_compat(t, mem::MaybeUninit::new(t)); // MaybeUninit is `repr(transparent)`
}

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

// These must work for *any* type, since we guarantee that `repr(transparent)` is ABI-compatible
// with the wrapped field.
test_abi_newtype(());
// FIXME: this still fails! test_abi_newtype(Zst);
test_abi_newtype(0u32);
test_abi_newtype(0f32);
test_abi_newtype((0u32, 1u32, 2u32));
test_abi_newtype([0u32, 1u32, 2u32]);
test_abi_newtype([0i32; 0]);
// FIXME: skipping the array tests on mips64 due to https://github.com/rust-lang/rust/issues/115404
if !cfg!(target_arch = "mips64") {
test_abi_newtype([0u32, 1u32, 2u32]);
test_abi_newtype([0i32; 0]);
}
}
16 changes: 9 additions & 7 deletions src/tools/miri/tests/pass/panic/catch_panic.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// We test the `align_offset` panic below, make sure we test the interpreter impl and not the "real" one.
//@compile-flags: -Zmiri-symbolic-alignment-check -Zmiri-permissive-provenance
//@compile-flags: -Zmiri-symbolic-alignment-check
#![feature(never_type)]
#![allow(unconditional_panic, non_fmt_panics)]

Expand Down Expand Up @@ -48,14 +48,16 @@ fn main() {
}));

// Std panics
test(None, |_old_val| std::panic!("Hello from panic: std"));
test(None, |old_val| std::panic::panic_any(format!("Hello from panic: {:?}", old_val)));
test(None, |old_val| std::panic!("Hello from panic: {:?}", old_val));
test(None, |_old_val| std::panic!("Hello from std::panic"));
test(None, |old_val| std::panic!("Hello from std::panic: {:?}", old_val));
test(None, |old_val| {
std::panic::panic_any(format!("Hello from std::panic_any: {:?}", old_val))
});
test(None, |_old_val| std::panic::panic_any(1337));

// Core panics
test(None, |_old_val| core::panic!("Hello from panic: core"));
test(None, |old_val| core::panic!("Hello from panic: {:?}", old_val));
test(None, |_old_val| core::panic!("Hello from core::panic"));
test(None, |old_val| core::panic!("Hello from core::panic: {:?}", old_val));

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

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

Expand Down
20 changes: 10 additions & 10 deletions src/tools/miri/tests/pass/panic/catch_panic.stderr
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
thread 'main' panicked at $DIR/catch_panic.rs:LL:CC:
Hello from panic: std
Hello from std::panic
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Caught panic message (&str): Hello from panic: std
Caught panic message (&str): Hello from std::panic
thread 'main' panicked at $DIR/catch_panic.rs:LL:CC:
Hello from panic: 1
Caught panic message (String): Hello from panic: 1
Hello from std::panic: 1
Caught panic message (String): Hello from std::panic: 1
thread 'main' panicked at $DIR/catch_panic.rs:LL:CC:
Hello from panic: 2
Caught panic message (String): Hello from panic: 2
Hello from std::panic_any: 2
Caught panic message (String): Hello from std::panic_any: 2
thread 'main' panicked at $DIR/catch_panic.rs:LL:CC:
Box<dyn Any>
Failed to get caught panic message.
thread 'main' panicked at $DIR/catch_panic.rs:LL:CC:
Hello from panic: core
Caught panic message (&str): Hello from panic: core
Hello from core::panic
Caught panic message (&str): Hello from core::panic
thread 'main' panicked at $DIR/catch_panic.rs:LL:CC:
Hello from panic: 5
Caught panic message (String): Hello from panic: 5
Hello from core::panic: 5
Caught panic message (String): Hello from core::panic: 5
thread 'main' panicked at $DIR/catch_panic.rs:LL:CC:
index out of bounds: the len is 3 but the index is 4
Caught panic message (String): index out of bounds: the len is 3 but the index is 4
Expand Down
4 changes: 2 additions & 2 deletions src/tools/miri/tests/pass/panic/nested_panic_caught.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@normalize-stderr-test: "\| +\^+" -> "| ^"
//@normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> "$1"
//@normalize-stderr-test: "\n at [^\n]+" -> "$1"
//@normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> ""
//@normalize-stderr-test: "\n +at [^\n]+" -> ""

// Checks that nested panics work correctly.

Expand Down
Loading

0 comments on commit b30b535

Please sign in to comment.