Skip to content

Commit 06b8c3e

Browse files
Rely only on base alignment and offset for computing field alignment
Fix #54028
1 parent 70073ec commit 06b8c3e

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

Diff for: src/librustc_codegen_llvm/mir/place.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,7 @@ impl PlaceRef<'ll, 'tcx> {
173173
let cx = bx.cx;
174174
let field = self.layout.field(cx, ix);
175175
let offset = self.layout.fields.offset(ix);
176-
let effective_field_align = self.align
177-
.min(self.layout.align)
178-
.min(field.align)
179-
.restrict_for_offset(offset);
176+
let effective_field_align = self.align.restrict_for_offset(offset);
180177

181178
let simple = || {
182179
// Unions and newtypes only use an offset of 0.

Diff for: src/test/codegen/align-struct.rs

+10
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ pub fn align64(i : i32) -> Align64 {
4848
a64
4949
}
5050

51+
// For issue 54028: make sure that we are specifying the correct alignment for fields of aligned
52+
// structs
53+
// CHECK-LABEL: @align64_load
54+
#[no_mangle]
55+
pub fn align64_load(a: Align64) -> i32 {
56+
// CHECK: [[FIELD:%.*]] = bitcast %Align64* %{{.*}} to i32*
57+
// CHECK: {{%.*}} = load i32, i32* [[FIELD]], align 64
58+
a.0
59+
}
60+
5161
// CHECK-LABEL: @nested64
5262
#[no_mangle]
5363
pub fn nested64(a: Align64, b: i32, c: i32, d: i8) -> Nested64 {

0 commit comments

Comments
 (0)