From ff080a943979ffd8876340376a8f1129c5eb2c80 Mon Sep 17 00:00:00 2001 From: David Renshaw Date: Sun, 15 Apr 2018 11:29:46 -0400 Subject: [PATCH] update for https://github.com/rust-lang/rust/pull/49669 --- src/eval_context.rs | 15 +++++++++++++-- src/terminator/mod.rs | 13 ++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/eval_context.rs b/src/eval_context.rs index 667a86a..46fafd3 100644 --- a/src/eval_context.rs +++ b/src/eval_context.rs @@ -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 @@ -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, } diff --git a/src/terminator/mod.rs b/src/terminator/mod.rs index 4e9fecd..21c1346 100644 --- a/src/terminator/mod.rs +++ b/src/terminator/mod.rs @@ -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()?; @@ -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()?; @@ -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()?; @@ -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] {