Skip to content

Commit a69cc85

Browse files
committed
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.
2 parents 37b1f6c + 1a2eb49 commit a69cc85

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

src/librustc_trans/mir/operand.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,20 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
338338

339339
let a = base::from_immediate(bcx, a);
340340
let b = base::from_immediate(bcx, b);
341-
bcx.store(a, bcx.struct_gep(lldest, ix0), f_align);
342-
bcx.store(b, bcx.struct_gep(lldest, ix1), f_align);
341+
342+
// See comment above about zero-sized values.
343+
let (a_zst, b_zst) = common::type_pair_fields(bcx.ccx, operand.ty)
344+
.map_or((false, false), |[a_ty, b_ty]| {
345+
(common::type_is_zero_size(bcx.ccx, a_ty),
346+
common::type_is_zero_size(bcx.ccx, b_ty))
347+
});
348+
349+
if !a_zst {
350+
bcx.store(a, bcx.struct_gep(lldest, ix0), f_align);
351+
}
352+
if !b_zst {
353+
bcx.store(b, bcx.struct_gep(lldest, ix1), f_align);
354+
}
343355
}
344356
}
345357
}

src/test/codegen/mir_zst_stores.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
#![crate_type = "lib"]
1414
use std::marker::PhantomData;
1515

16-
16+
#[derive(Copy, Clone)]
1717
struct Zst { phantom: PhantomData<Zst> }
1818

1919
// CHECK-LABEL: @mir
20+
// CHECK-NOT: store{{.*}}undef
2021
#[no_mangle]
21-
fn mir(){
22-
// CHECK-NOT: getelementptr
23-
// CHECK-NOT: store{{.*}}undef
22+
fn mir() {
2423
let x = Zst { phantom: PhantomData };
24+
let y = (x, 0);
25+
drop(y);
26+
drop((0, x));
2527
}

0 commit comments

Comments
 (0)