diff --git a/rust-version b/rust-version index 1733872825..9e4ddf2aca 100644 --- a/rust-version +++ b/rust-version @@ -1 +1 @@ -7e08576e4276a97b523c25bfd196d419c39c7b87 +088b987307b91612ab164026e1dcdd0129fdb62b diff --git a/src/eval.rs b/src/eval.rs index a1157af0e3..91a563fa56 100644 --- a/src/eval.rs +++ b/src/eval.rs @@ -35,8 +35,16 @@ pub fn create_ecx<'mir, 'tcx: 'mir>( Evaluator::new(), ); + // FIXME(https://github.com/rust-lang/miri/pull/803): no validation on Windows. + let target_os = ecx.tcx.tcx.sess.target.target.target_os.to_lowercase(); + let validate = if target_os == "windows" { + false + } else { + config.validate + }; + // FIXME: InterpretCx::new should take an initial MemoryExtra - ecx.memory_mut().extra = MemoryExtra::new(config.seed.map(StdRng::seed_from_u64), config.validate); + ecx.memory_mut().extra = MemoryExtra::new(config.seed.map(StdRng::seed_from_u64), validate); let main_instance = ty::Instance::mono(ecx.tcx.tcx, main_id); let main_mir = ecx.load_mir(main_instance.def)?; diff --git a/src/shims/foreign_items.rs b/src/shims/foreign_items.rs index d43374f1bc..2a3644e45c 100644 --- a/src/shims/foreign_items.rs +++ b/src/shims/foreign_items.rs @@ -50,8 +50,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx ) -> InterpResult<'tcx> { let this = self.eval_context_mut(); if !this.is_null(ptr)? { + let ptr = this.force_ptr(ptr)?; this.memory_mut().deallocate( - ptr.to_ptr()?, + ptr, None, MiriMemoryKind::C.into(), )?; @@ -78,7 +79,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx Ok(Scalar::Ptr(new_ptr)) } } else { - let old_ptr = old_ptr.to_ptr()?; + let old_ptr = this.force_ptr(old_ptr)?; let memory = this.memory_mut(); let old_size = Size::from_bytes(memory.get(old_ptr.alloc_id)?.bytes.len() as u64); if new_size == 0 { @@ -234,7 +235,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx this.write_scalar(Scalar::Ptr(ptr), dest)?; } "__rust_dealloc" => { - let ptr = this.read_scalar(args[0])?.to_ptr()?; + let ptr = this.read_scalar(args[0])?.not_undef()?; let old_size = this.read_scalar(args[1])?.to_usize(this)?; let align = this.read_scalar(args[2])?.to_usize(this)?; if old_size == 0 { @@ -243,6 +244,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx if !align.is_power_of_two() { return err!(HeapAllocNonPowerOfTwoAlignment(align)); } + let ptr = this.force_ptr(ptr)?; this.memory_mut().deallocate( ptr, Some((Size::from_bytes(old_size), Align::from_bytes(align).unwrap())), diff --git a/test-cargo-miri/run-test.py b/test-cargo-miri/run-test.py index 73515c74e4..a9aba008e9 100755 --- a/test-cargo-miri/run-test.py +++ b/test-cargo-miri/run-test.py @@ -52,8 +52,9 @@ def test_cargo_miri_run(): ) def test_cargo_miri_test(): + # FIXME: enable validation again, once that no longer conflicts with intptrcast test("cargo miri test", - cargo_miri("test") + ["--", "-Zmiri-seed=feed"], + cargo_miri("test") + ["--", "-Zmiri-seed=feed", "-Zmiri-disable-validation"], "test.stdout.ref", "test.stderr.ref" ) test("cargo miri test (with filter)", diff --git a/tests/compiletest.rs b/tests/compiletest.rs index 1d32d3a732..076deca6a3 100644 --- a/tests/compiletest.rs +++ b/tests/compiletest.rs @@ -112,7 +112,9 @@ fn run_pass_miri(opt: bool) { } fn compile_fail_miri(opt: bool) { - compile_fail("tests/compile-fail", &get_target(), opt); + if !cfg!(windows) { // FIXME re-enable on Windows + compile_fail("tests/compile-fail", &get_target(), opt); + } } fn test_runner(_tests: &[&()]) { diff --git a/tests/run-pass-noseed/intptrcast.rs b/tests/run-pass-noseed/intptrcast.rs index 40b21f9a47..1b5251c911 100644 --- a/tests/run-pass-noseed/intptrcast.rs +++ b/tests/run-pass-noseed/intptrcast.rs @@ -1,8 +1,13 @@ // compile-flags: -Zmiri-seed=0000000000000000 +// This returns a miri pointer at type usize, if the argument is a proper pointer +fn transmute_ptr_to_int(x: *const T) -> usize { + unsafe { std::mem::transmute(x) } +} + fn main() { // Some casting-to-int with arithmetic. - let x = &42 as *const i32 as usize; + let x = &42 as *const i32 as usize; let y = x * 2; assert_eq!(y, x + x); let z = y as u8 as usize; @@ -11,4 +16,11 @@ fn main() { // Pointer string formatting! We can't check the output as it changes when libstd changes, // but we can make sure Miri does not error. format!("{:?}", &mut 13 as *mut _); + + // Check that intptrcast is triggered for explicit casts and that it is consistent with + // transmuting. + let a: *const i32 = &42; + let b = transmute_ptr_to_int(a) as u8; + let c = a as usize as u8; + assert_eq!(b, c); } diff --git a/tests/run-pass-noseed/ptr_int_casts.rs b/tests/run-pass-noseed/ptr_int_casts.rs index c279024f35..ebf65ac3fe 100644 --- a/tests/run-pass-noseed/ptr_int_casts.rs +++ b/tests/run-pass-noseed/ptr_int_casts.rs @@ -1,3 +1,4 @@ +// FIXME move this to run-pass, it should work with intptrcast. use std::mem; use std::ptr; diff --git a/tests/run-pass/ptr_offset.rs b/tests/run-pass-noseed/ptr_offset.rs similarity index 85% rename from tests/run-pass/ptr_offset.rs rename to tests/run-pass-noseed/ptr_offset.rs index 1c7f0eb717..a836e02812 100644 --- a/tests/run-pass/ptr_offset.rs +++ b/tests/run-pass-noseed/ptr_offset.rs @@ -1,3 +1,5 @@ +// FIXME move this to run-pass, it should work with intptrcast. + fn f() -> i32 { 42 } fn main() {