Skip to content

Commit

Permalink
rustc: don't unpack newtypes of scalar-pairs with mismatched alignment.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Dec 1, 2017
1 parent bb42071 commit d455955
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/librustc/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions src/test/codegen/packed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit d455955

Please sign in to comment.