From f9c768864a7784c518b6ac1af6515950c6eff6ec Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Mon, 14 Oct 2019 09:08:39 -0500 Subject: [PATCH] Use places instead of ptrs to write packed immtys --- src/helpers.rs | 18 +++++++----------- src/shims/time.rs | 12 ++++++------ tests/run-pass/clock.rs | 1 + 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/helpers.rs b/src/helpers.rs index 3012b1a955..9107958e01 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -318,27 +318,23 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx // Writes several `ImmTy`s contiguosly into memory. This is useful when you have to pack // different values into a struct. - fn write_immediates( + fn write_packed_immediates( &mut self, - ptr: &Pointer, + place: &MPlaceTy<'tcx, Tag>, imms: &[ImmTy<'tcx, Tag>], ) -> InterpResult<'tcx> { let this = self.eval_context_mut(); let tcx = &{ this.tcx.tcx }; - let allocation = this.memory_mut().get_mut(ptr.alloc_id)?; let mut offset = Size::from_bytes(0); - for imm in imms { - let size = imm.layout.size; - allocation.write_scalar( - tcx, - ptr.offset(offset, tcx)?, - imm.to_scalar()?.into(), - size, + for &imm in imms { + this.write_immediate_to_mplace( + *imm, + place.offset(offset, None, imm.layout, tcx)?, )?; - offset += size; + offset += imm.layout.size; } Ok(()) diff --git a/src/shims/time.rs b/src/shims/time.rs index 1b799b1330..0153c1a912 100644 --- a/src/shims/time.rs +++ b/src/shims/time.rs @@ -10,7 +10,7 @@ use crate::*; fn get_time<'tcx>() -> InterpResult<'tcx, Duration> { SystemTime::now() .duration_since(SystemTime::UNIX_EPOCH) - .map_err(|_| err_unsup_format!("Time went backwards").into()) + .map_err(|_| err_unsup_format!("Times before the Unix epoch are not supported").into()) } fn int_to_immty_checked<'tcx>( @@ -52,7 +52,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx return Ok(-1); } - let tp = this.force_ptr(this.read_scalar(tp_op)?.not_undef()?)?; + let tp = this.deref_operand(tp_op)?; let duration = get_time()?; let tv_sec = duration.as_secs() as i128; @@ -63,11 +63,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx int_to_immty_checked(tv_nsec, this.libc_ty_layout("c_long")?)?, ]; - this.write_immediates(&tp, &imms)?; + this.write_packed_immediates(&tp, &imms)?; Ok(0) } - // Foreign function used by generic unix + // Foreign function used by generic unix (in particular macOS) fn gettimeofday( &mut self, tv_op: OpTy<'tcx, Tag>, @@ -86,7 +86,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx return Ok(-1); } - let tv = this.force_ptr(this.read_scalar(tv_op)?.not_undef()?)?; + let tv = this.deref_operand(tv_op)?; let duration = get_time()?; let tv_sec = duration.as_secs() as i128; @@ -97,7 +97,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx int_to_immty_checked(tv_usec, this.libc_ty_layout("suseconds_t")?)?, ]; - this.write_immediates(&tv, &imms)?; + this.write_packed_immediates(&tv, &imms)?; Ok(0) } diff --git a/tests/run-pass/clock.rs b/tests/run-pass/clock.rs index 987a78fe1f..23f45f91ad 100644 --- a/tests/run-pass/clock.rs +++ b/tests/run-pass/clock.rs @@ -1,3 +1,4 @@ +// ignore-windows: TODO clock shims are not implemented on Windows // compile-flags: -Zmiri-disable-isolation use std::time::SystemTime;