Skip to content

Commit db9d4b1

Browse files
eddybmichaelwoerister
authored andcommitted
rustc: don't unpack newtypes of scalar-pairs with mismatched alignment.
1 parent 6b15f7d commit db9d4b1

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/librustc/ty/layout.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,9 @@ impl<'a, 'tcx> LayoutDetails {
10831083
// We have exactly one non-ZST field.
10841084
(Some((i, field)), None, None) => {
10851085
// Field fills the struct and it has a scalar or scalar pair ABI.
1086-
if offsets[i].bytes() == 0 && size == field.size {
1086+
if offsets[i].bytes() == 0 &&
1087+
align.abi() == field.align.abi() &&
1088+
size == field.size {
10871089
match field.abi {
10881090
// For plain scalars we can't unpack newtypes
10891091
// for `#[repr(C)]`, as that affects C ABIs.

src/test/codegen/packed.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,14 @@ pub fn pkd_pair(pair1: &mut PackedPair, pair2: &mut PackedPair) {
5757
// CHECK: call void @llvm.memcpy.{{.*}}(i8* %{{.*}}, i8* %{{.*}}, i{{[0-9]+}} 5, i32 1, i1 false)
5858
*pair2 = *pair1;
5959
}
60+
61+
#[repr(packed)]
62+
#[derive(Copy, Clone)]
63+
pub struct PackedNestedPair((u32, u32));
64+
65+
// CHECK-LABEL: @pkd_nested_pair
66+
#[no_mangle]
67+
pub fn pkd_nested_pair(pair1: &mut PackedNestedPair, pair2: &mut PackedNestedPair) {
68+
// CHECK: call void @llvm.memcpy.{{.*}}(i8* %{{.*}}, i8* %{{.*}}, i{{[0-9]+}} 8, i32 1, i1 false)
69+
*pair2 = *pair1;
70+
}

0 commit comments

Comments
 (0)