]> git.lizzy.rs Git - rust.git/commitdiff
rustc_trans: do not store pair fields if they are ZSTs.
authorEduard-Mihai Burtescu <edy.burt@gmail.com>
Tue, 6 Jun 2017 18:13:13 +0000 (21:13 +0300)
committerEduard-Mihai Burtescu <edy.burt@gmail.com>
Tue, 6 Jun 2017 18:13:13 +0000 (21:13 +0300)
src/librustc_trans/mir/operand.rs
src/test/codegen/mir_zst_stores.rs

index a12d0fec1cdd06f31a0a00bb07562f4b06967933..1b8a05b6f6c746b125a1fbc7dfac71797d507a1b 100644 (file)
@@ -338,8 +338,20 @@ pub fn store_operand(&mut self,
 
                 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);
+                }
             }
         }
     }
index a2cedc853a1e6dbf6a41beb9fce51950a096733b..36602196cefebe38e3bcfcb2e9341f43a3896aa2 100644 (file)
 #![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));
 }