diff options
| author | Eduard Burtescu <edy.burt@gmail.com> | 2016-06-09 18:15:15 +0300 |
|---|---|---|
| committer | Eduard Burtescu <edy.burt@gmail.com> | 2016-06-20 23:18:21 +0300 |
| commit | bec32eb4ff6d9f19a02441269916dec5cb348927 (patch) | |
| tree | 58193dd849b81f7ff70a2bf320977e37f24a342e | |
| parent | eb9cb4dbca6eab5b7a50934fe7385e1a99d9dc62 (diff) | |
| download | rust-bec32eb4ff6d9f19a02441269916dec5cb348927.tar.gz rust-bec32eb4ff6d9f19a02441269916dec5cb348927.zip | |
trans: noop drops don't need their lvalue in an alloca.
| -rw-r--r-- | src/librustc_trans/mir/analyze.rs | 11 | ||||
| -rw-r--r-- | src/librustc_trans/mir/block.rs | 7 |
2 files changed, 15 insertions, 3 deletions
diff --git a/src/librustc_trans/mir/analyze.rs b/src/librustc_trans/mir/analyze.rs index 93ac002f2a9..65581d43f88 100644 --- a/src/librustc_trans/mir/analyze.rs +++ b/src/librustc_trans/mir/analyze.rs @@ -18,6 +18,7 @@ use rustc::mir::repr::TerminatorKind; use rustc::mir::visit::{Visitor, LvalueContext}; use rustc::mir::traversal; use common::{self, Block, BlockAndBuilder}; +use glue; use super::rvalue; pub fn lvalue_temps<'bcx,'tcx>(bcx: Block<'bcx,'tcx>, @@ -138,13 +139,21 @@ impl<'mir, 'bcx, 'tcx> Visitor<'tcx> for TempAnalyzer<'mir, 'bcx, 'tcx> { LvalueContext::Consume => { } LvalueContext::Store | - LvalueContext::Drop | LvalueContext::Inspect | LvalueContext::Borrow { .. } | LvalueContext::Slice { .. } | LvalueContext::Projection => { self.mark_as_lvalue(temp.index()); } + LvalueContext::Drop => { + let ty = self.mir.temp_decls[index as usize].ty; + let ty = self.bcx.monomorphize(&ty); + + // Only need the lvalue if we're actually dropping it. + if glue::type_needs_drop(self.bcx.tcx(), ty) { + self.mark_as_lvalue(index as usize); + } + } } } _ => { diff --git a/src/librustc_trans/mir/block.rs b/src/librustc_trans/mir/block.rs index bdcf3dd8cd4..4591fa28578 100644 --- a/src/librustc_trans/mir/block.rs +++ b/src/librustc_trans/mir/block.rs @@ -196,13 +196,16 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> { } mir::TerminatorKind::Drop { ref location, target, unwind } => { - let lvalue = self.trans_lvalue(&bcx, location); - let ty = lvalue.ty.to_ty(bcx.tcx()); + let ty = mir.lvalue_ty(bcx.tcx(), location).to_ty(bcx.tcx()); + let ty = bcx.monomorphize(&ty); + // Double check for necessity to drop if !glue::type_needs_drop(bcx.tcx(), ty) { funclet_br(self, bcx, target); return; } + + let lvalue = self.trans_lvalue(&bcx, location); let drop_fn = glue::get_drop_glue(bcx.ccx(), ty); let drop_ty = glue::get_drop_glue_type(bcx.tcx(), ty); let llvalue = if drop_ty != ty { |
