Re: Bug#916818: rustc: Compiler regression results in generated code with unaligned access
On 12/21/18 12:55 PM, John Paul Adrian Glaubitz wrote:
> On 12/21/18 10:19 AM, John Paul Adrian Glaubitz wrote:
>> Attaching a better patch which can be applied unconditionally.
>
> Attaching a cleaned up patch after James' comments.
And here with better formatting as well.
Adrian
--
.''`. John Paul Adrian Glaubitz
: :' : Debian Developer - glaubitz@debian.org
`. `' Freie Universitaet Berlin - glaubitz@physik.fu-berlin.de
`- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913
Description: Fix alignment regression on sparc64
Author: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Bug: https://github.com/rust-lang/rust/issues/56927
Last-Update: 2018-12-20
Index: rustc-1.31.0+dfsg1/src/librustc_codegen_llvm/mir/place.rs
===================================================================
--- rustc-1.31.0+dfsg1.orig/src/librustc_codegen_llvm/mir/place.rs
+++ rustc-1.31.0+dfsg1/src/librustc_codegen_llvm/mir/place.rs
@@ -177,7 +177,14 @@ impl PlaceRef<'ll, 'tcx> {
let cx = bx.cx;
let field = self.layout.field(cx, ix);
let offset = self.layout.fields.offset(ix);
- let effective_field_align = self.align.restrict_for_offset(offset);
+
+ #[cfg(target_arch = "sparc64")]
+ let effective_field_align = self.align
+ .min(self.layout.align)
+ .min(field.align)
+ .restrict_for_offset(offset);
+ #[cfg(not(target_arch = "sparc64"))]
+ let effective_field_align = self.align.restrict_for_offset(offset);
let simple = || {
// Unions and newtypes only use an offset of 0.
Index: rustc-1.31.0+dfsg1/src/test/codegen/align-struct.rs
===================================================================
--- rustc-1.31.0+dfsg1.orig/src/test/codegen/align-struct.rs
+++ rustc-1.31.0+dfsg1/src/test/codegen/align-struct.rs
@@ -52,6 +52,7 @@ pub fn align64(i : i32) -> Align64 {
// structs
// CHECK-LABEL: @align64_load
#[no_mangle]
+#[cfg_attr(not(target_arch = "sparc64"))]
pub fn align64_load(a: Align64) -> i32 {
// CHECK: [[FIELD:%.*]] = bitcast %Align64* %{{.*}} to i32*
// CHECK: {{%.*}} = load i32, i32* [[FIELD]], align 64
Reply to: