Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
dwrensha committed Apr 15, 2018
1 parent 7ade1c4 commit ff080a9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
15 changes: 13 additions & 2 deletions src/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,10 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
(Value::ByValPair(data, _), false) => {
self.write_value(ValTy { value: Value::ByVal(data), ty: dest_ty }, dest)?;
},
(Value::ByVal(_), _) => bug!("expected fat ptr"),
(Value::ByVal(v), false) => {
self.write_value(ValTy { value: Value::ByVal(v), ty: dest_ty }, dest)?;
}
(Value::ByVal(_), true) => bug!("expected fat ptr"),
}
} else {
// First, try casting
Expand Down Expand Up @@ -711,7 +714,15 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
fn type_is_fat_ptr(&self, ty: Ty<'tcx>) -> bool {
match ty.sty {
ty::TyRawPtr(ref tam) |
ty::TyRef(_, ref tam) => !self.type_is_sized(tam.ty),
ty::TyRef(_, ref tam) => {
if let ty::TyForeign(def_id) = tam.ty.sty {
if "Opaque" == self.tcx.item_name(def_id) {
// TODO make this more picky. We want it to only match std::alloc::Opaque.
return false;
}
}
!self.type_is_sized(tam.ty)
}
ty::TyAdt(def, _) if def.is_box() => !self.type_is_sized(ty.boxed_ty()),
_ => false,
}
Expand Down
13 changes: 6 additions & 7 deletions src/terminator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
return Ok(());
}

"alloc::heap::::__rust_alloc" => {
"alloc::alloc::::__rust_alloc" => {
let usize = self.tcx.types.usize;
let size = self.value_to_primval(args[0], usize)?.to_u64()?;
let align = self.value_to_primval(args[1], usize)?.to_u64()?;
Expand All @@ -716,7 +716,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
return Ok(());
}

"alloc::heap::::__rust_alloc_zeroed" => {
"alloc::alloc::::__rust_alloc_zeroed" => {
let usize = self.tcx.types.usize;
let size = self.value_to_primval(args[0], usize)?.to_u64()?;
let align = self.value_to_primval(args[1], usize)?.to_u64()?;
Expand Down Expand Up @@ -798,7 +798,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
return Ok(());
}

"alloc::heap::::__rust_realloc" => {
"alloc::alloc::::__rust_realloc" => {
let (lval, block) = destination.expect("realloc() does not diverge");
let dest_ptr = self.force_allocation(lval)?.to_ptr()?;

Expand All @@ -809,17 +809,16 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {

let usize = self.tcx.types.usize;
let _old_size = self.value_to_primval(args[1], usize)?.to_u64()?;
let _old_align = self.value_to_primval(args[2], usize)?.to_u64()?;
let align = self.value_to_primval(args[2], usize)?.to_u64()?;
let new_size = self.value_to_primval(args[3], usize)?.to_u64()?;
let new_align = self.value_to_primval(args[4], usize)?.to_u64()?;

let new_ptr = self.memory.reallocate(ptr, new_size, new_align)?;
let new_ptr = self.memory.reallocate(ptr, new_size, align)?;
self.memory.write_ptr(dest_ptr, new_ptr)?;
self.goto_block(block);
return Ok(());
}

"alloc::heap::::__rust_dealloc" => {
"alloc::alloc::::__rust_dealloc" => {
let (_lval, block) = destination.expect("dealloc() does not diverge");

let ptr = match args[0] {
Expand Down

0 comments on commit ff080a9

Please sign in to comment.