Auto merge of #42486 - eddyb:issue-39882, r=nikomatsakis

rustc_trans: do not store pair fields if they are ZSTs.

Should help with #39882 even if it's not a complete fix AFAICT.
This commit is contained in:
bors 2017-06-07 12:34:13 +00:00
commit a69cc85909
2 changed files with 20 additions and 6 deletions

View File

@ -338,9 +338,21 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
let a = base::from_immediate(bcx, a);
let b = base::from_immediate(bcx, b);
// 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);
}
}
}
}
}

View File

@ -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));
}