-
Notifications
You must be signed in to change notification settings - Fork 745
codegen: Use target pointer size consistently for layout calculations #1289
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
96bba97
ir: Grab target information from clang.
emilio 473cfc2
codegen: Use target pointer size consistently for layout calculations.
emilio fa12451
codegen: Don't skip alignment checks if we support repr align.
emilio ae0fdf7
Now that we have stuff that depends on libclang-5 we need to do this.
emilio 21ff022
ci: Update before_install to handle target change in LLVM's server.
emilio 26a1717
Adjust .travis.yml to only use maj-min versions.
emilio a5eb2df
Use clang 4.0.0, not 4.0.1, since the later doesn't have an ubuntu pa…
emilio de0d850
Add -x to the CI script.
emilio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ use ir::layout::Layout; | |
use ir::ty::{Type, TypeKind}; | ||
use quote; | ||
use std::cmp; | ||
use std::mem; | ||
|
||
/// Trace the layout of struct. | ||
#[derive(Debug)] | ||
|
@@ -101,7 +100,7 @@ impl<'a> StructLayoutTracker<'a> { | |
pub fn saw_vtable(&mut self) { | ||
debug!("saw vtable for {}", self.name); | ||
|
||
let ptr_size = mem::size_of::<*mut ()>(); | ||
let ptr_size = self.ctx.target_pointer_size(); | ||
self.latest_offset += ptr_size; | ||
self.latest_field_layout = Some(Layout::new(ptr_size, ptr_size)); | ||
self.max_field_align = ptr_size; | ||
|
@@ -165,15 +164,13 @@ impl<'a> StructLayoutTracker<'a> { | |
// can support. | ||
// | ||
// This means that the structs in the array are super-unsafe to | ||
// access, since they won't be properly aligned, but *shrug*. | ||
if let Some(layout) = self.ctx.resolve_type(inner).layout( | ||
self.ctx, | ||
) | ||
{ | ||
if layout.align > mem::size_of::<*mut ()>() { | ||
field_layout.size = align_to(layout.size, layout.align) * | ||
len; | ||
field_layout.align = mem::size_of::<*mut ()>(); | ||
// access, since they won't be properly aligned, but there's not too | ||
// much we can do about it. | ||
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. For posterity, we can use |
||
if let Some(layout) = self.ctx.resolve_type(inner).layout(self.ctx) { | ||
if layout.align > self.ctx.target_pointer_size() { | ||
field_layout.size = | ||
align_to(layout.size, layout.align) * len; | ||
field_layout.align = self.ctx.target_pointer_size(); | ||
} | ||
} | ||
} | ||
|
@@ -193,7 +190,7 @@ impl<'a> StructLayoutTracker<'a> { | |
|
||
// Otherwise the padding is useless. | ||
let need_padding = padding_bytes >= field_layout.align || | ||
field_layout.align > mem::size_of::<*mut ()>(); | ||
field_layout.align > self.ctx.target_pointer_size(); | ||
|
||
self.latest_offset += padding_bytes; | ||
|
||
|
@@ -215,7 +212,7 @@ impl<'a> StructLayoutTracker<'a> { | |
if need_padding && padding_bytes != 0 { | ||
Some(Layout::new( | ||
padding_bytes, | ||
cmp::min(field_layout.align, mem::size_of::<*mut ()>()), | ||
cmp::min(field_layout.align, self.ctx.target_pointer_size()) | ||
)) | ||
} else { | ||
None | ||
|
@@ -267,15 +264,15 @@ impl<'a> StructLayoutTracker<'a> { | |
(self.last_field_was_bitfield && | ||
padding_bytes >= | ||
self.latest_field_layout.unwrap().align) || | ||
layout.align > mem::size_of::<*mut ()>()) | ||
layout.align > self.ctx.target_pointer_size()) | ||
{ | ||
let layout = if self.is_packed { | ||
Layout::new(padding_bytes, 1) | ||
} else if self.last_field_was_bitfield || | ||
layout.align > mem::size_of::<*mut ()>() | ||
layout.align > self.ctx.target_pointer_size() | ||
{ | ||
// We've already given up on alignment here. | ||
Layout::for_size(padding_bytes) | ||
Layout::for_size(self.ctx, padding_bytes) | ||
} else { | ||
Layout::new(padding_bytes, layout.align) | ||
}; | ||
|
@@ -289,8 +286,18 @@ impl<'a> StructLayoutTracker<'a> { | |
} | ||
|
||
pub fn requires_explicit_align(&self, layout: Layout) -> bool { | ||
self.max_field_align < layout.align && | ||
layout.align <= mem::size_of::<*mut ()>() | ||
if self.max_field_align >= layout.align { | ||
return false; | ||
} | ||
// At this point we require explicit alignment, but we may not be able | ||
// to generate the right bits, let's double check. | ||
if self.ctx.options().rust_features().repr_align { | ||
return true; | ||
} | ||
|
||
// We can only generate up-to a word of alignment unless we support | ||
// repr(align). | ||
layout.align <= self.ctx.target_pointer_size() | ||
} | ||
|
||
fn padding_bytes(&self, layout: Layout) -> usize { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Oh, nice -- this is the API you sent patches upstream to add, right?
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.
Right :)