Skip to content

Commit 2724b6c

Browse files
committed
Use places instead of ptrs to write packed immtys
1 parent 50618b5 commit 2724b6c

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

src/helpers.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -318,27 +318,23 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
318318

319319
// Writes several `ImmTy`s contiguosly into memory. This is useful when you have to pack
320320
// different values into a struct.
321-
fn write_immediates(
321+
fn write_packed_immediates(
322322
&mut self,
323-
ptr: &Pointer<Tag>,
323+
place: &MPlaceTy<'tcx, Tag>,
324324
imms: &[ImmTy<'tcx, Tag>],
325325
) -> InterpResult<'tcx> {
326326
let this = self.eval_context_mut();
327327

328328
let tcx = &{ this.tcx.tcx };
329329

330-
let allocation = this.memory_mut().get_mut(ptr.alloc_id)?;
331330
let mut offset = Size::from_bytes(0);
332331

333-
for imm in imms {
334-
let size = imm.layout.size;
335-
allocation.write_scalar(
336-
tcx,
337-
ptr.offset(offset, tcx)?,
338-
imm.to_scalar()?.into(),
339-
size,
332+
for &imm in imms {
333+
this.write_immediate_to_mplace(
334+
*imm,
335+
place.offset(offset, None, imm.layout, tcx)?,
340336
)?;
341-
offset += size;
337+
offset += imm.layout.size;
342338
}
343339

344340
Ok(())

src/shims/time.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
5252
return Ok(-1);
5353
}
5454

55-
let tp = this.force_ptr(this.read_scalar(tp_op)?.not_undef()?)?;
55+
let tp = this.deref_operand(tp_op)?;
5656

5757
let duration = get_time()?;
5858
let tv_sec = duration.as_secs() as i128;
@@ -63,7 +63,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
6363
int_to_immty_checked(tv_nsec, this.libc_ty_layout("c_long")?)?,
6464
];
6565

66-
this.write_immediates(&tp, &imms)?;
66+
this.write_packed_immediates(&tp, &imms)?;
6767

6868
Ok(0)
6969
}
@@ -86,7 +86,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
8686
return Ok(-1);
8787
}
8888

89-
let tv = this.force_ptr(this.read_scalar(tv_op)?.not_undef()?)?;
89+
let tv = this.deref_operand(tv_op)?;
9090

9191
let duration = get_time()?;
9292
let tv_sec = duration.as_secs() as i128;
@@ -97,7 +97,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
9797
int_to_immty_checked(tv_usec, this.libc_ty_layout("suseconds_t")?)?,
9898
];
9999

100-
this.write_immediates(&tv, &imms)?;
100+
// let tv_ty = this.tcx.tcx.mk_tup(imms.iter().map(|imm| imm.layout.ty));
101+
// let tv_local = Local::from(tv);
102+
// let tv_place = PlaceTy{ place: tv_local.into(), layout: tv_ty.layout};
103+
this.write_packed_immediates(&tv, &imms)?;
101104

102105
Ok(0)
103106
}

0 commit comments

Comments
 (0)