Skip to content

Commit

Permalink
Auto merge of #53536 - RalfJung:array-drop, r=eddyb
Browse files Browse the repository at this point in the history
fix array drop glue: properly turn raw ptr into reference

Discovered while working on #53424: The generated drop glue uses an assignment `ptr = cur` where `ptr` is a reference and `cur` a raw pointer. This is not well-formed MIR.

Do we have MIR sanity checks that run on the drop glue and should have caught this?

r? @eddyb
  • Loading branch information
bors committed Aug 22, 2018
2 parents 329dde5 + 0447b50 commit c24f27c
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/librustc_mir/util/elaborate_drops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ impl<'l, 'b, 'tcx, D> DropCtxt<'l, 'b, 'tcx, D>
/// if can_go then succ else drop-block
/// drop-block:
/// if ptr_based {
/// ptr = cur
/// ptr = &mut *cur
/// cur = cur.offset(1)
/// } else {
/// ptr = &mut P[cur]
Expand Down Expand Up @@ -591,7 +591,14 @@ impl<'l, 'b, 'tcx, D> DropCtxt<'l, 'b, 'tcx, D>

let one = self.constant_usize(1);
let (ptr_next, cur_next) = if ptr_based {
(Rvalue::Use(copy(&Place::Local(cur))),
(Rvalue::Ref(
tcx.types.re_erased,
BorrowKind::Mut { allow_two_phase_borrow: false },
Place::Projection(Box::new(Projection {
base: Place::Local(cur),
elem: ProjectionElem::Deref,
}))
),
Rvalue::BinaryOp(BinOp::Offset, copy(&Place::Local(cur)), one))
} else {
(Rvalue::Ref(
Expand Down Expand Up @@ -736,7 +743,7 @@ impl<'l, 'b, 'tcx, D> DropCtxt<'l, 'b, 'tcx, D>
if ptr_based {
let tmp_ty = tcx.mk_mut_ptr(self.place_ty(self.place));
let tmp = Place::Local(self.new_temp(tmp_ty));
// tmp = &P;
// tmp = &mut P;
// cur = tmp as *mut T;
// end = Offset(cur, len);
drop_block_stmts.push(self.assign(&tmp, Rvalue::Ref(
Expand Down

0 comments on commit c24f27c

Please sign in to comment.