Skip to content

Commit ce4461f

Browse files
committed
Auto merge of #38511 - Mark-Simulacrum:drop-glue, r=eddyb
Make drop glue for unsized value pass two arguments instead of *(data, meta) Fixes #36457 r? @eddyb
2 parents 99913c5 + afc2dcd commit ce4461f

File tree

6 files changed

+137
-226
lines changed

6 files changed

+137
-226
lines changed

src/librustc_llvm/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,8 @@ pub fn mk_section_iter(llof: ObjectFileRef) -> SectionIter {
270270
/// Safe wrapper around `LLVMGetParam`, because segfaults are no fun.
271271
pub fn get_param(llfn: ValueRef, index: c_uint) -> ValueRef {
272272
unsafe {
273-
assert!(index < LLVMCountParams(llfn));
273+
assert!(index < LLVMCountParams(llfn),
274+
"out of bounds argument access: {} out of {} arguments", index, LLVMCountParams(llfn));
274275
LLVMGetParam(llfn, index)
275276
}
276277
}

src/librustc_trans/callee.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use base::*;
2727
use common::{
2828
self, CrateContext, FunctionContext, SharedCrateContext
2929
};
30+
use adt::MaybeSizedValue;
3031
use consts;
3132
use declare;
3233
use value::Value;
@@ -364,7 +365,7 @@ fn trans_fn_once_adapter_shim<'a, 'tcx>(
364365

365366
// Call the by-ref closure body with `self` in a cleanup scope,
366367
// to drop `self` when the body returns, or in case it unwinds.
367-
let self_scope = fcx.schedule_drop_mem(llenv, closure_ty);
368+
let self_scope = fcx.schedule_drop_mem(MaybeSizedValue::sized(llenv), closure_ty);
368369

369370
let llfn = callee.reify(bcx.ccx);
370371
let llret;

src/librustc_trans/cleanup.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
//! corresponds to a normal exit from a block (for example, an expression
1919
//! completing evaluation successfully without panic).
2020
21-
use llvm::{BasicBlockRef, ValueRef};
21+
use llvm::BasicBlockRef;
2222
use base;
23+
use adt::MaybeSizedValue;
2324
use common::{BlockAndBuilder, FunctionContext, Funclet};
2425
use glue;
2526
use type_::Type;
26-
use value::Value;
2727
use rustc::ty::Ty;
2828

2929
pub struct CleanupScope<'tcx> {
@@ -36,7 +36,7 @@ pub struct CleanupScope<'tcx> {
3636

3737
#[derive(Copy, Clone)]
3838
pub struct DropValue<'tcx> {
39-
val: ValueRef,
39+
val: MaybeSizedValue,
4040
ty: Ty<'tcx>,
4141
skip_dtor: bool,
4242
}
@@ -94,16 +94,14 @@ impl<'tcx> DropValue<'tcx> {
9494

9595
impl<'a, 'tcx> FunctionContext<'a, 'tcx> {
9696
/// Schedules a (deep) drop of `val`, which is a pointer to an instance of `ty`
97-
pub fn schedule_drop_mem(&self, val: ValueRef, ty: Ty<'tcx>) -> CleanupScope<'tcx> {
97+
pub fn schedule_drop_mem(&self, val: MaybeSizedValue, ty: Ty<'tcx>) -> CleanupScope<'tcx> {
9898
if !self.ccx.shared().type_needs_drop(ty) { return CleanupScope::noop(); }
9999
let drop = DropValue {
100100
val: val,
101101
ty: ty,
102102
skip_dtor: false,
103103
};
104104

105-
debug!("schedule_drop_mem(val={:?}, ty={:?}) skip_dtor={}", Value(val), ty, drop.skip_dtor);
106-
107105
CleanupScope::new(self, drop)
108106
}
109107

@@ -112,7 +110,8 @@ impl<'a, 'tcx> FunctionContext<'a, 'tcx> {
112110
/// `ty`. The scheduled code handles extracting the discriminant
113111
/// and dropping the contents associated with that variant
114112
/// *without* executing any associated drop implementation.
115-
pub fn schedule_drop_adt_contents(&self, val: ValueRef, ty: Ty<'tcx>) -> CleanupScope<'tcx> {
113+
pub fn schedule_drop_adt_contents(&self, val: MaybeSizedValue, ty: Ty<'tcx>)
114+
-> CleanupScope<'tcx> {
116115
// `if` below could be "!contents_needs_drop"; skipping drop
117116
// is just an optimization, so sound to be conservative.
118117
if !self.ccx.shared().type_needs_drop(ty) { return CleanupScope::noop(); }
@@ -123,9 +122,6 @@ impl<'a, 'tcx> FunctionContext<'a, 'tcx> {
123122
skip_dtor: true,
124123
};
125124

126-
debug!("schedule_drop_adt_contents(val={:?}, ty={:?}) skip_dtor={}",
127-
Value(val), ty, drop.skip_dtor);
128-
129125
CleanupScope::new(self, drop)
130126
}
131127
}

0 commit comments

Comments
 (0)