rustc_trans: use an Lvalue Datum for an unsized lvalue to avoid bogus drops.

This commit is contained in:
Eduard Burtescu 2015-02-24 08:22:43 +02:00
parent 3b0cafbcd7
commit 8659de0334
2 changed files with 7 additions and 12 deletions

View file

@ -214,14 +214,7 @@ pub fn type_needs_unwind_cleanup<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<
}
pub fn type_needs_drop<'tcx>(cx: &ty::ctxt<'tcx>, ty: Ty<'tcx>) -> bool {
// Unsized types cannot be dropped automatically - these are lvalues pointing
// to alloca's containing the actual data pointer (and the unsizing info),
// which only be obtained by dereferencing a pointer from which moves are
// not allowed. Datum & friends could possibly be adjusted to avoid getting
// this far - maybe the (*data, info) aggregate could be an SSA value?
// Lvalues don't have to be pointers, just behave like a pointer, but there
// is no telling what other implicit assumptions are lurking around.
ty::type_contents(cx, ty).needs_drop(cx) && type_is_sized(cx, ty)
ty::type_contents(cx, ty).needs_drop(cx)
}
fn type_is_newtype_immediate<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool {

View file

@ -463,11 +463,13 @@ fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
let ptr_ty = type_of::in_memory_type_of(bcx.ccx(), unsized_ty).ptr_to();
let base = PointerCast(bcx, lval.val, ptr_ty);
let scratch = rvalue_scratch_datum(bcx, unsized_ty, "__fat_ptr");
Store(bcx, base, get_dataptr(bcx, scratch.val));
Store(bcx, info, get_len(bcx, scratch.val));
let llty = type_of::type_of(bcx.ccx(), unsized_ty);
// HACK(eddyb) get around issues with lifetime intrinsics.
let scratch = alloca_no_lifetime(bcx, llty, "__fat_ptr");
Store(bcx, base, get_dataptr(bcx, scratch));
Store(bcx, info, get_len(bcx, scratch));
DatumBlock::new(bcx, scratch.to_expr_datum())
DatumBlock::new(bcx, Datum::new(scratch, unsized_ty, LvalueExpr))
}
fn unsize_unique_vec<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,