Skip to content

Commit 6025926

Browse files
committed
auto merge of #16838 : nick29581/rust/dst-bug-4, r=pnkfelix,nikomatsakis
Don't double free embedded, unsized slices. Merge/rebase error from DST. Thanks to @eddyb for finding. Closes #16826 (I hope) r?
2 parents f6a7ab4 + 415d7e8 commit 6025926

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/librustc/middle/trans/glue.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,11 @@ fn make_drop_glue<'a>(bcx: &'a Block<'a>, v0: ValueRef, t: ty::t) -> &'a Block<'
403403
ty::ty_uniq(content_ty) => {
404404
match ty::get(content_ty).sty {
405405
ty::ty_vec(ty, None) => {
406-
tvec::make_drop_glue_unboxed(bcx, v0, ty)
406+
tvec::make_drop_glue_unboxed(bcx, v0, ty, true)
407407
}
408408
ty::ty_str => {
409409
let unit_ty = ty::sequence_element_type(bcx.tcx(), t);
410-
tvec::make_drop_glue_unboxed(bcx, v0, unit_ty)
410+
tvec::make_drop_glue_unboxed(bcx, v0, unit_ty, true)
411411
}
412412
ty::ty_trait(..) => {
413413
let lluniquevalue = GEPi(bcx, v0, [0, abi::trt_field_box]);
@@ -507,7 +507,7 @@ fn make_drop_glue<'a>(bcx: &'a Block<'a>, v0: ValueRef, t: ty::t) -> &'a Block<'
507507
None);
508508
bcx
509509
}
510-
ty::ty_vec(ty, None) => tvec::make_drop_glue_unboxed(bcx, v0, ty),
510+
ty::ty_vec(ty, None) => tvec::make_drop_glue_unboxed(bcx, v0, ty, false),
511511
_ => {
512512
assert!(ty::type_is_sized(bcx.tcx(), t));
513513
if ty::type_needs_drop(bcx.tcx(), t) &&

src/librustc/middle/trans/tvec.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,31 @@ pub fn pointer_add_byte(bcx: &Block, ptr: ValueRef, bytes: ValueRef) -> ValueRef
5454
pub fn make_drop_glue_unboxed<'a>(
5555
bcx: &'a Block<'a>,
5656
vptr: ValueRef,
57-
unit_ty: ty::t)
57+
unit_ty: ty::t,
58+
should_deallocate: bool)
5859
-> &'a Block<'a> {
5960
let not_null = IsNotNull(bcx, vptr);
6061
with_cond(bcx, not_null, |bcx| {
6162
let tcx = bcx.tcx();
6263
let _icx = push_ctxt("tvec::make_drop_glue_unboxed");
6364

64-
let len = get_len(bcx, vptr);
6565
let dataptr = get_dataptr(bcx, vptr);
6666
let bcx = if ty::type_needs_drop(tcx, unit_ty) {
67+
let len = get_len(bcx, vptr);
6768
iter_vec_raw(bcx, dataptr, unit_ty, len, glue::drop_ty)
6869
} else {
6970
bcx
7071
};
7172

72-
let not_null = IsNotNull(bcx, dataptr);
73-
with_cond(bcx, not_null, |bcx| {
74-
glue::trans_exchange_free(bcx, dataptr, 0, 8)
75-
})
73+
if should_deallocate {
74+
let not_null = IsNotNull(bcx, dataptr);
75+
with_cond(bcx, not_null, |bcx| {
76+
// FIXME: #13994: the old `Box<[T]>` will not support sized deallocation
77+
glue::trans_exchange_free(bcx, dataptr, 0, 8)
78+
})
79+
} else {
80+
bcx
81+
}
7682
})
7783
}
7884

0 commit comments

Comments
 (0)