Skip to content

Commit

Permalink
Move zero-sized type handling logic to new_operand
Browse files Browse the repository at this point in the history
`new_operand` now checks the type it's given and either creates the nil
value itself, or produces an empty operand.
  • Loading branch information
Aatch committed Apr 28, 2016
1 parent 89edd96 commit c55d9e5
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/librustc_trans/mir/mod.rs
Expand Up @@ -16,7 +16,7 @@ use rustc::mir::repr as mir;
use rustc::mir::tcx::LvalueTy;
use session::config::FullDebugInfo;
use base;
use common::{self, Block, BlockAndBuilder, FunctionContext};
use common::{self, Block, BlockAndBuilder, CrateContext, FunctionContext};
use debuginfo::{self, declare_local, DebugLoc, VariableAccess, VariableKind};
use machine;
use type_of;
Expand Down Expand Up @@ -109,12 +109,21 @@ enum TempRef<'tcx> {
}

impl<'tcx> TempRef<'tcx> {
fn new_operand(val: OperandValue, ty: ty::Ty<'tcx>) -> TempRef<'tcx> {
let op = OperandRef {
val: val,
ty: ty
};
TempRef::Operand(Some(op))
fn new_operand<'bcx>(ccx: &CrateContext<'bcx, 'tcx>,
ty: ty::Ty<'tcx>) -> TempRef<'tcx> {
if common::type_is_zero_size(ccx, ty) {
// Zero-size temporaries aren't always initialized, which
// doesn't matter because they don't contain data, but
// we need something in the operand.
let val = OperandValue::Immediate(common::C_nil(ccx));
let op = OperandRef {
val: val,
ty: ty
};
TempRef::Operand(Some(op))
} else {
TempRef::Operand(None)
}
}
}

Expand Down Expand Up @@ -160,17 +169,11 @@ pub fn trans_mir<'blk, 'tcx: 'blk>(fcx: &'blk FunctionContext<'blk, 'tcx>) {
TempRef::Lvalue(LvalueRef::alloca(&bcx,
mty,
&format!("temp{:?}", i)))
} else if common::type_is_zero_size(bcx.ccx(), mty) {
// Zero-size temporaries aren't always initialized, which
// doesn't matter because they don't contain data, but
// we need something in the operand.
let val = OperandValue::Immediate(common::C_nil(bcx.ccx()));
TempRef::new_operand(val, mty)
} else {
// If this is an immediate temp, we do not create an
// alloca in advance. Instead we wait until we see the
// definition and update the operand there.
TempRef::Operand(None)
TempRef::new_operand(bcx.ccx(), mty)
})
.collect();

Expand Down

0 comments on commit c55d9e5

Please sign in to comment.