Skip to content
Snippets Groups Projects
Commit f2d895a6 authored by David Renshaw's avatar David Renshaw
Browse files

Pointer::with_primval_offset()

parent bc5e76e1
No related branches found
No related tags found
No related merge requests found
......@@ -363,17 +363,12 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
PrimVal::Bytes(elem_size as u128),
PrimValKind::U64);
match self.memory.constraints.add_binop_constraint(
let offset = self.memory.constraints.add_binop_constraint(
mir::BinOp::Add,
p.offset.as_primval(),
byte_index,
PrimValKind::U64) {
PrimVal::Abstract(sbytes) => {
PrimVal::Ptr(Pointer::new_abstract(p.alloc_id, sbytes))
}
_ => unreachable!(),
}
PrimValKind::U64);
PrimVal::Ptr(Pointer::with_primval_offset(p.alloc_id, offset))
}
(Err(_), 0) => base_ptr,
(Err(e), _) => return Err(e),
......
......@@ -96,6 +96,15 @@ impl Pointer {
Pointer { alloc_id, offset: PointerOffset::Abstract(offset), }
}
pub fn with_primval_offset(alloc_id: AllocId, offset: PrimVal) -> Self {
match offset {
PrimVal::Abstract(sbytes) => Pointer::new_abstract(alloc_id, sbytes),
PrimVal::Bytes(b) => Pointer::new(alloc_id, b as u64),
PrimVal::Undef => panic!("tried to construct pointer with undefined offset"),
PrimVal::Ptr(_) => panic!("tried to construct point with pointer offset"),
}
}
pub fn has_concrete_offset(self) -> bool {
match self.offset {
PointerOffset::Concrete(_) => true,
......
......@@ -331,12 +331,8 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
ptr.to_ptr()?.offset.as_primval(),
byte_offset,
PrimValKind::U64);
if let PrimVal::Abstract(sbytes) = new_offset {
let new_ptr = Pointer::new_abstract(ptr.to_ptr()?.alloc_id, sbytes);
let new_ptr = Pointer::with_primval_offset(ptr.to_ptr()?.alloc_id, new_offset);
self.write_primval(dest, PrimVal::Ptr(new_ptr), dest_ty)?;
} else {
unreachable!()
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment