Skip to content

Commit

Permalink
Use places instead of ptrs to write packed immtys
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdrz committed Oct 14, 2019
1 parent 50618b5 commit f9c7688
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
18 changes: 7 additions & 11 deletions src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Tag>,
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(())
Expand Down
12 changes: 6 additions & 6 deletions src/shims/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>(
Expand Down Expand Up @@ -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;
Expand All @@ -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>,
Expand All @@ -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;
Expand All @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions tests/run-pass/clock.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ignore-windows: TODO clock shims are not implemented on Windows
// compile-flags: -Zmiri-disable-isolation

use std::time::SystemTime;
Expand Down

0 comments on commit f9c7688

Please sign in to comment.