-
Notifications
You must be signed in to change notification settings - Fork 13.3k
rustc_codegen_llvm: don't assume offsets are always aligned. #53998
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -174,7 +174,10 @@ impl PlaceRef<'ll, 'tcx> { | |
let cx = bx.cx; | ||
let field = self.layout.field(cx, ix); | ||
let offset = self.layout.fields.offset(ix); | ||
let align = self.align.min(self.layout.align).min(field.align); | ||
let effective_field_align = self.align | ||
.min(self.layout.align) | ||
.min(field.align) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might help #54028 to remove this line, and rely strictly on the alignment of the type, combined with the best-case alignment for the offset. That way, we can hint LLVM about alignments that are higher than it can figure out by itself. Do we want to do that and do we expect a performance improvement? |
||
.restrict_for_offset(offset); | ||
|
||
let simple = || { | ||
// Unions and newtypes only use an offset of 0. | ||
|
@@ -196,7 +199,7 @@ impl PlaceRef<'ll, 'tcx> { | |
None | ||
}, | ||
layout: field, | ||
align, | ||
align: effective_field_align, | ||
} | ||
}; | ||
|
||
|
@@ -269,7 +272,7 @@ impl PlaceRef<'ll, 'tcx> { | |
llval: bx.pointercast(byte_ptr, ll_fty.ptr_to()), | ||
llextra: self.llextra, | ||
layout: field, | ||
align, | ||
align: effective_field_align, | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#[repr(u16)] | ||
enum DeviceKind { | ||
Nil = 0, | ||
} | ||
|
||
#[repr(packed)] | ||
struct DeviceInfo { | ||
endianness: u8, | ||
device_kind: DeviceKind, | ||
} | ||
|
||
fn main() { | ||
let _x = None::<(DeviceInfo, u8)>; | ||
let _y = None::<(DeviceInfo, u16)>; | ||
let _z = None::<(DeviceInfo, u64)>; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why isn't
field.align
set up properly here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok.