Move zero-sized type handling logic to new_operand

`new_operand` now checks the type it's given and either creates the nil
value itself, or produces an empty operand.
This commit is contained in:
James Miller 2016-04-17 14:37:52 +12:00
parent 89edd96be8
commit c55d9e591b

View file

@ -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;
@ -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)
}
}
}
@ -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();