Skip to content

Commit c55d9e5

Browse files
committed
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.
1 parent 89edd96 commit c55d9e5

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

src/librustc_trans/mir/mod.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc::mir::repr as mir;
1616
use rustc::mir::tcx::LvalueTy;
1717
use session::config::FullDebugInfo;
1818
use base;
19-
use common::{self, Block, BlockAndBuilder, FunctionContext};
19+
use common::{self, Block, BlockAndBuilder, CrateContext, FunctionContext};
2020
use debuginfo::{self, declare_local, DebugLoc, VariableAccess, VariableKind};
2121
use machine;
2222
use type_of;
@@ -109,12 +109,21 @@ enum TempRef<'tcx> {
109109
}
110110

111111
impl<'tcx> TempRef<'tcx> {
112-
fn new_operand(val: OperandValue, ty: ty::Ty<'tcx>) -> TempRef<'tcx> {
113-
let op = OperandRef {
114-
val: val,
115-
ty: ty
116-
};
117-
TempRef::Operand(Some(op))
112+
fn new_operand<'bcx>(ccx: &CrateContext<'bcx, 'tcx>,
113+
ty: ty::Ty<'tcx>) -> TempRef<'tcx> {
114+
if common::type_is_zero_size(ccx, ty) {
115+
// Zero-size temporaries aren't always initialized, which
116+
// doesn't matter because they don't contain data, but
117+
// we need something in the operand.
118+
let val = OperandValue::Immediate(common::C_nil(ccx));
119+
let op = OperandRef {
120+
val: val,
121+
ty: ty
122+
};
123+
TempRef::Operand(Some(op))
124+
} else {
125+
TempRef::Operand(None)
126+
}
118127
}
119128
}
120129

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

0 commit comments

Comments
 (0)