Re: Bug#916818: rustc: Compiler regression results in generated code with unaligned access
Hi!
On 12/20/18 9:40 AM, John Paul Adrian Glaubitz wrote:
> If that's not feasible, I can also create a patch which changes the alignment
> behavior specific to sparc64 in the code, so the patch can be applied to all
> platforms.
>
> I'm still waiting for an opinion from upstream how this issue is going to
> be fixed. They do consider it a bug as the alignment should always be correct.
Attaching a better patch which can be applied unconditionally.
Also, the span patch for sparc64 can be dropped. Just tested that.
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(any(target_arch = "sparc64", target_arch = "sparcv9")))]
pub fn align64_load(a: Align64) -> i32 {
// CHECK: [[FIELD:%.*]] = bitcast %Align64* %{{.*}} to i32*
// CHECK: {{%.*}} = load i32, i32* [[FIELD]], align 64
Reply to: