From d4559554454e8dc6eff2b7002baff2a5372e3dda Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Fri, 1 Dec 2017 18:36:58 +0200 Subject: [PATCH] rustc: don't unpack newtypes of scalar-pairs with mismatched alignment. --- src/librustc/ty/layout.rs | 4 +++- src/test/codegen/packed.rs | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs index 7d262adffdb98..b2ed34cb91305 100644 --- a/src/librustc/ty/layout.rs +++ b/src/librustc/ty/layout.rs @@ -1079,7 +1079,9 @@ impl<'a, 'tcx> LayoutDetails { // We have exactly one non-ZST field. (Some((i, field)), None, None) => { // Field fills the struct and it has a scalar or scalar pair ABI. - if offsets[i].bytes() == 0 && size == field.size { + if offsets[i].bytes() == 0 && + align.abi() == field.align.abi() && + size == field.size { match field.abi { // For plain scalars we can't unpack newtypes // for `#[repr(C)]`, as that affects C ABIs. diff --git a/src/test/codegen/packed.rs b/src/test/codegen/packed.rs index dd530cf03cd41..022f581278c2f 100644 --- a/src/test/codegen/packed.rs +++ b/src/test/codegen/packed.rs @@ -57,3 +57,14 @@ pub fn pkd_pair(pair1: &mut PackedPair, pair2: &mut PackedPair) { // CHECK: call void @llvm.memcpy.{{.*}}(i8* %{{.*}}, i8* %{{.*}}, i{{[0-9]+}} 5, i32 1, i1 false) *pair2 = *pair1; } + +#[repr(packed)] +#[derive(Copy, Clone)] +pub struct PackedNestedPair((u32, u32)); + +// CHECK-LABEL: @pkd_nested_pair +#[no_mangle] +pub fn pkd_nested_pair(pair1: &mut PackedNestedPair, pair2: &mut PackedNestedPair) { +// CHECK: call void @llvm.memcpy.{{.*}}(i8* %{{.*}}, i8* %{{.*}}, i{{[0-9]+}} 8, i32 1, i1 false) + *pair2 = *pair1; +}