about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJames Miller <james@aatch.net>2016-04-17 14:37:52 +1200
committerJames Miller <james@aatch.net>2016-04-28 13:18:51 +1200
commitc55d9e591b1f66d4677dac2efda6b70afcd4b345 (patch)
tree12fa5c77af08580d47e92b484c1a51f351eda8d2
parent89edd96be86fd65d63f63a208062c8baf86e7d7c (diff)
downloadrust-c55d9e591b1f66d4677dac2efda6b70afcd4b345.tar.gz
rust-c55d9e591b1f66d4677dac2efda6b70afcd4b345.zip
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.
-rw-r--r--src/librustc_trans/mir/mod.rs31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/librustc_trans/mir/mod.rs b/src/librustc_trans/mir/mod.rs
index b7661ce039c..75d9ca32a21 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();