From c55d9e591b1f66d4677dac2efda6b70afcd4b345 Mon Sep 17 00:00:00 2001 From: James Miller Date: Sun, 17 Apr 2016 14:37:52 +1200 Subject: [PATCH] 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. --- src/librustc_trans/mir/mod.rs | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/librustc_trans/mir/mod.rs b/src/librustc_trans/mir/mod.rs index b7661ce039ca3..75d9ca32a21de 100644 --- a/src/librustc_trans/mir/mod.rs +++ b/src/librustc_trans/mir/mod.rs @@ -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();