Skip to content

Commit

Permalink
trans: noop drops don't need their lvalue in an alloca.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Jun 20, 2016
1 parent eb9cb4d commit bec32eb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/librustc_trans/mir/analyze.rs
Expand Up @@ -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>,
Expand Down Expand Up @@ -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);
}
}
}
}
_ => {
Expand Down
7 changes: 5 additions & 2 deletions src/librustc_trans/mir/block.rs
Expand Up @@ -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 {
Expand Down

0 comments on commit bec32eb

Please sign in to comment.