diff --git a/rust-version b/rust-version index 6e980a4e22..b1fd330a9d 100644 --- a/rust-version +++ b/rust-version @@ -1 +1 @@ -e6cef0445779724b469ab7b9a8d3c05d9e848ca8 +42abbd8878d3b67238f3611b0587c704ba94f39c diff --git a/src/machine.rs b/src/machine.rs index 26ff23511f..3c59837305 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -6,6 +6,7 @@ use std::cell::RefCell; use std::num::NonZeroU64; use std::rc::Rc; use std::time::Instant; +use std::fmt; use log::trace; use rand::rngs::StdRng; @@ -69,6 +70,31 @@ impl Into> for MiriMemoryKind { } } +impl MayLeak for MiriMemoryKind { + #[inline(always)] + fn may_leak(self) -> bool { + use self::MiriMemoryKind::*; + match self { + Rust | C | WinHeap | Env => false, + Machine | Global => true, + } + } +} + +impl fmt::Display for MiriMemoryKind { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + use self::MiriMemoryKind::*; + match self { + Rust => write!(f, "Rust heap"), + C => write!(f, "C heap"), + WinHeap => write!(f, "Windows heap"), + Machine => write!(f, "machine-managed memory"), + Env => write!(f, "environment variable"), + Global => write!(f, "global"), + } + } +} + /// Extra per-allocation data #[derive(Debug, Clone)] pub struct AllocExtra { @@ -525,14 +551,3 @@ impl AllocationExtra for AllocExtra { } } } - -impl MayLeak for MiriMemoryKind { - #[inline(always)] - fn may_leak(self) -> bool { - use self::MiriMemoryKind::*; - match self { - Rust | C | WinHeap | Env => false, - Machine | Global => true, - } - } -} diff --git a/tests/compile-fail/stack_free.rs b/tests/compile-fail/stack_free.rs index ea09d3e2b4..50a590e448 100644 --- a/tests/compile-fail/stack_free.rs +++ b/tests/compile-fail/stack_free.rs @@ -1,7 +1,7 @@ // Validation/SB changes why we fail // compile-flags: -Zmiri-disable-validation -Zmiri-disable-stacked-borrows -// error-pattern: deallocating `Stack` memory using `Machine(Rust)` deallocation operation +// error-pattern: deallocating stack variable memory using Rust heap deallocation operation fn main() { let x = 42; diff --git a/tests/run-pass/leak-in-static.rs b/tests/run-pass/leak-in-static.rs new file mode 100644 index 0000000000..b12cbbf6e6 --- /dev/null +++ b/tests/run-pass/leak-in-static.rs @@ -0,0 +1,8 @@ +static mut LEAKER: Option>> = None; + +fn main() { + // Having memory "leaked" in globals is allowed. + unsafe { + LEAKER = Some(Box::new(vec![0; 42])); + } +} diff --git a/tests/run-pass/panic/catch_panic.rs b/tests/run-pass/panic/catch_panic.rs index 6408c940d9..7689b85f76 100644 --- a/tests/run-pass/panic/catch_panic.rs +++ b/tests/run-pass/panic/catch_panic.rs @@ -77,9 +77,6 @@ fn main() { test(None, |_old_val| { debug_assert!(false); loop {} }); test(None, |_old_val| { unsafe { (1 as *const i32).read() }; loop {} }); // trigger debug-assertion in libstd - // Cleanup: reset to default hook. - drop(std::panic::take_hook()); - eprintln!("Success!"); // Make sure we get this in stderr }