mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-06 04:08:40 +00:00
rustc_codegen_llvm: don't overalign loads of pair operands.
This commit is contained in:
parent
b68fc18c45
commit
51cf4e9e91
@ -589,9 +589,11 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
|
|||||||
});
|
});
|
||||||
OperandValue::Immediate(to_immediate(self, llval, place.layout))
|
OperandValue::Immediate(to_immediate(self, llval, place.layout))
|
||||||
} else if let layout::Abi::ScalarPair(ref a, ref b) = place.layout.abi {
|
} else if let layout::Abi::ScalarPair(ref a, ref b) = place.layout.abi {
|
||||||
let mut load = |i, scalar: &layout::Scalar| {
|
let b_offset = a.value.size(self).align_to(b.value.align(self).abi);
|
||||||
|
|
||||||
|
let mut load = |i, scalar: &layout::Scalar, align| {
|
||||||
let llptr = self.struct_gep(place.llval, i as u64);
|
let llptr = self.struct_gep(place.llval, i as u64);
|
||||||
let load = self.load(llptr, place.align);
|
let load = self.load(llptr, align);
|
||||||
scalar_load_metadata(self, load, scalar);
|
scalar_load_metadata(self, load, scalar);
|
||||||
if scalar.is_bool() {
|
if scalar.is_bool() {
|
||||||
self.trunc(load, self.cx().type_i1())
|
self.trunc(load, self.cx().type_i1())
|
||||||
@ -599,7 +601,11 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
|
|||||||
load
|
load
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
OperandValue::Pair(load(0, a), load(1, b))
|
|
||||||
|
OperandValue::Pair(
|
||||||
|
load(0, a, place.align),
|
||||||
|
load(1, b, place.align.restrict_for_offset(b_offset)),
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
OperandValue::Ref(place.llval, None, place.align)
|
OperandValue::Ref(place.llval, None, place.align)
|
||||||
};
|
};
|
||||||
|
18
src/test/codegen/issue-56267-2.rs
Normal file
18
src/test/codegen/issue-56267-2.rs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
// compile-flags: -C no-prepopulate-passes
|
||||||
|
|
||||||
|
#![crate_type="rlib"]
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub struct Foo<T> {
|
||||||
|
foo: u64,
|
||||||
|
bar: T,
|
||||||
|
}
|
||||||
|
|
||||||
|
// The load from bar.1 should have alignment 4. Not checking
|
||||||
|
// other loads here, as the alignment will be platform-dependent.
|
||||||
|
|
||||||
|
// CHECK: %{{.+}} = load i32, i32* %{{.+}}, align 4
|
||||||
|
#[no_mangle]
|
||||||
|
pub fn test(x: Foo<(i32, i32)>) -> (i32, i32) {
|
||||||
|
x.bar
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user