about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEduard-Mihai Burtescu <edy.burt@gmail.com>2017-06-06 21:13:13 +0300
committerEduard-Mihai Burtescu <edy.burt@gmail.com>2017-06-06 21:13:13 +0300
commit1a2eb4953e2939a0bebeb56ae4a5715fd968a9ae (patch)
tree4b3c81c78a7f0822e2d3ad125b69851f8d408d0a
parentc94a9ac8ae33e6580940e02abb425dd2fe69b5d8 (diff)
downloadrust-1a2eb4953e2939a0bebeb56ae4a5715fd968a9ae.tar.gz
rust-1a2eb4953e2939a0bebeb56ae4a5715fd968a9ae.zip
rustc_trans: do not store pair fields if they are ZSTs.
-rw-r--r--src/librustc_trans/mir/operand.rs16
-rw-r--r--src/test/codegen/mir_zst_stores.rs10
2 files changed, 20 insertions, 6 deletions
diff --git a/src/librustc_trans/mir/operand.rs b/src/librustc_trans/mir/operand.rs
index a12d0fec1cd..1b8a05b6f6c 100644
--- a/src/librustc_trans/mir/operand.rs
+++ b/src/librustc_trans/mir/operand.rs
@@ -338,8 +338,20 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
 
                 let a = base::from_immediate(bcx, a);
                 let b = base::from_immediate(bcx, b);
-                bcx.store(a, bcx.struct_gep(lldest, ix0), f_align);
-                bcx.store(b, bcx.struct_gep(lldest, ix1), f_align);
+
+                // See comment above about zero-sized values.
+                let (a_zst, b_zst) = common::type_pair_fields(bcx.ccx, operand.ty)
+                    .map_or((false, false), |[a_ty, b_ty]| {
+                        (common::type_is_zero_size(bcx.ccx, a_ty),
+                         common::type_is_zero_size(bcx.ccx, b_ty))
+                    });
+
+                if !a_zst {
+                    bcx.store(a, bcx.struct_gep(lldest, ix0), f_align);
+                }
+                if !b_zst {
+                    bcx.store(b, bcx.struct_gep(lldest, ix1), f_align);
+                }
             }
         }
     }
diff --git a/src/test/codegen/mir_zst_stores.rs b/src/test/codegen/mir_zst_stores.rs
index a2cedc853a1..36602196cef 100644
--- a/src/test/codegen/mir_zst_stores.rs
+++ b/src/test/codegen/mir_zst_stores.rs
@@ -13,13 +13,15 @@
 #![crate_type = "lib"]
 use std::marker::PhantomData;
 
-
+#[derive(Copy, Clone)]
 struct Zst { phantom: PhantomData<Zst> }
 
 // CHECK-LABEL: @mir
+// CHECK-NOT: store{{.*}}undef
 #[no_mangle]
-fn mir(){
-    // CHECK-NOT: getelementptr
-    // CHECK-NOT: store{{.*}}undef
+fn mir() {
     let x = Zst { phantom: PhantomData };
+    let y = (x, 0);
+    drop(y);
+    drop((0, x));
 }