diff options
| author | Ariel Ben-Yehuda <ariel.byd@gmail.com> | 2017-05-11 01:02:52 +0300 |
|---|---|---|
| committer | Ariel Ben-Yehuda <ariel.byd@gmail.com> | 2017-05-28 10:43:24 +0300 |
| commit | 9da2aaccfe7dd3452dd066bbc3829af6bd76ace4 (patch) | |
| tree | f911577590ac319c17e22dba38b06d4ad31207d3 /src/librustc_trans | |
| parent | 5d2512ec5b03a1155054df881e40e35fc87d6351 (diff) | |
| download | rust-9da2aaccfe7dd3452dd066bbc3829af6bd76ace4.tar.gz rust-9da2aaccfe7dd3452dd066bbc3829af6bd76ace4.zip | |
translate array drop glue using MIR
This fixes leakage on panic with arrays & slices. I am using a C-style for-loop instead of a pointer-based loop because that would be ugly-er to implement.
Diffstat (limited to 'src/librustc_trans')
| -rw-r--r-- | src/librustc_trans/collector.rs | 12 | ||||
| -rw-r--r-- | src/librustc_trans/mir/block.rs | 31 |
2 files changed, 2 insertions, 41 deletions
diff --git a/src/librustc_trans/collector.rs b/src/librustc_trans/collector.rs index 5f8b79a994a..429e7b01610 100644 --- a/src/librustc_trans/collector.rs +++ b/src/librustc_trans/collector.rs @@ -612,17 +612,7 @@ fn visit_instance_use<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>, output.push(create_fn_trans_item(instance)); } } - ty::InstanceDef::DropGlue(_, Some(ty)) => { - match ty.sty { - ty::TyArray(ety, _) | - ty::TySlice(ety) - if is_direct_call => - { - // drop of arrays/slices is translated in-line. - visit_drop_use(scx, ety, false, output); - } - _ => {} - }; + ty::InstanceDef::DropGlue(_, Some(_)) => { output.push(create_fn_trans_item(instance)); } ty::InstanceDef::ClosureOnceShim { .. } | diff --git a/src/librustc_trans/mir/block.rs b/src/librustc_trans/mir/block.rs index a3fa1279ffb..724ff2f2134 100644 --- a/src/librustc_trans/mir/block.rs +++ b/src/librustc_trans/mir/block.rs @@ -20,13 +20,12 @@ use base::{self, Lifetime}; use callee; use builder::Builder; use common::{self, Funclet}; -use common::{C_bool, C_str_slice, C_struct, C_u32, C_uint, C_undef}; +use common::{C_bool, C_str_slice, C_struct, C_u32, C_undef}; use consts; use machine::llalign_of_min; use meth; use monomorphize; use type_of; -use tvec; use type_::Type; use rustc_data_structures::indexed_vec::IndexVec; @@ -222,34 +221,6 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> { let (drop_fn, need_extra) = match ty.sty { ty::TyDynamic(..) => (meth::DESTRUCTOR.get_fn(&bcx, lvalue.llextra), false), - ty::TyArray(ety, _) | ty::TySlice(ety) => { - // FIXME: handle panics - let drop_fn = monomorphize::resolve_drop_in_place( - bcx.ccx.shared(), ety); - let drop_fn = callee::get_fn(bcx.ccx, drop_fn); - let bcx = tvec::slice_for_each( - &bcx, - lvalue.project_index(&bcx, C_uint(bcx.ccx, 0u64)), - ety, - lvalue.len(bcx.ccx), - |bcx, llval, loop_bb| { - self.set_debug_loc(&bcx, terminator.source_info); - if let Some(unwind) = unwind { - bcx.invoke( - drop_fn, - &[llval], - loop_bb, - llblock(self, unwind), - cleanup_bundle - ); - } else { - bcx.call(drop_fn, &[llval], cleanup_bundle); - bcx.br(loop_bb); - } - }); - funclet_br(self, bcx, target); - return - } _ => (callee::get_fn(bcx.ccx, drop_fn), lvalue.has_extra()) }; let args = &[lvalue.llval, lvalue.llextra][..1 + need_extra as usize]; |
