Skip to content

Commit bec32eb

Browse files
committed
trans: noop drops don't need their lvalue in an alloca.
1 parent eb9cb4d commit bec32eb

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/librustc_trans/mir/analyze.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use rustc::mir::repr::TerminatorKind;
1818
use rustc::mir::visit::{Visitor, LvalueContext};
1919
use rustc::mir::traversal;
2020
use common::{self, Block, BlockAndBuilder};
21+
use glue;
2122
use super::rvalue;
2223

2324
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> {
138139
LvalueContext::Consume => {
139140
}
140141
LvalueContext::Store |
141-
LvalueContext::Drop |
142142
LvalueContext::Inspect |
143143
LvalueContext::Borrow { .. } |
144144
LvalueContext::Slice { .. } |
145145
LvalueContext::Projection => {
146146
self.mark_as_lvalue(temp.index());
147147
}
148+
LvalueContext::Drop => {
149+
let ty = self.mir.temp_decls[index as usize].ty;
150+
let ty = self.bcx.monomorphize(&ty);
151+
152+
// Only need the lvalue if we're actually dropping it.
153+
if glue::type_needs_drop(self.bcx.tcx(), ty) {
154+
self.mark_as_lvalue(index as usize);
155+
}
156+
}
148157
}
149158
}
150159
_ => {

src/librustc_trans/mir/block.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,16 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
196196
}
197197

198198
mir::TerminatorKind::Drop { ref location, target, unwind } => {
199-
let lvalue = self.trans_lvalue(&bcx, location);
200-
let ty = lvalue.ty.to_ty(bcx.tcx());
199+
let ty = mir.lvalue_ty(bcx.tcx(), location).to_ty(bcx.tcx());
200+
let ty = bcx.monomorphize(&ty);
201+
201202
// Double check for necessity to drop
202203
if !glue::type_needs_drop(bcx.tcx(), ty) {
203204
funclet_br(self, bcx, target);
204205
return;
205206
}
207+
208+
let lvalue = self.trans_lvalue(&bcx, location);
206209
let drop_fn = glue::get_drop_glue(bcx.ccx(), ty);
207210
let drop_ty = glue::get_drop_glue_type(bcx.tcx(), ty);
208211
let llvalue = if drop_ty != ty {

0 commit comments

Comments
 (0)