From: Christian Poveda Date: Mon, 14 Oct 2019 14:08:39 +0000 (-0500) Subject: Use places instead of ptrs to write packed immtys X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=f9c768864a7784c518b6ac1af6515950c6eff6ec;p=rust.git Use places instead of ptrs to write packed immtys --- diff --git a/src/helpers.rs b/src/helpers.rs index 3012b1a9554..9107958e010 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -318,27 +318,23 @@ fn libc_ty_layout(&mut self, name: &str) -> InterpResult<'tcx, TyLayout<'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 1b799b1330a..0153c1a912d 100644 --- a/src/shims/time.rs +++ b/src/shims/time.rs @@ -10,7 +10,7 @@ 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 @@ fn clock_gettime( 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 @@ fn clock_gettime( 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 @@ fn gettimeofday( 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 @@ fn gettimeofday( 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 987a78fe1f0..23f45f91ada 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;