diff options
author | Emilio Cobos Álvarez <emilio@crisal.io> | 2018-03-31 15:30:19 +0200 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2018-04-03 11:27:46 +0200 |
commit | fa1245198a0c61c13c0a8e6e02d431efe25ba0c9 (patch) | |
tree | 6a098f2e0e30bbc2ba703ee13183764b28758251 /src/codegen | |
parent | 473cfc29ff0b5a6a8f268d8a3069ffe9502edf90 (diff) |
codegen: Don't skip alignment checks if we support repr align.
Plus fix the check that avoids us generating explicit alignment fields for
structs aligned to more than pointer-size.
Fixes #1291
Diffstat (limited to 'src/codegen')
-rw-r--r-- | src/codegen/mod.rs | 5 | ||||
-rw-r--r-- | src/codegen/struct_layout.rs | 14 |
2 files changed, 15 insertions, 4 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 5411b2a0..39babb6b 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -1776,8 +1776,9 @@ impl CodeGenerator for CompInfo { let align = layout.align; let check_struct_align = - if align > ctx.target_pointer_size() { - // FIXME when [RFC 1358](https://github.com/rust-lang/rust/issues/33626) ready + if align > ctx.target_pointer_size() && + !ctx.options().rust_features().repr_align + { None } else { Some(quote! { diff --git a/src/codegen/struct_layout.rs b/src/codegen/struct_layout.rs index d2be5aff..3a641f4a 100644 --- a/src/codegen/struct_layout.rs +++ b/src/codegen/struct_layout.rs @@ -286,8 +286,18 @@ impl<'a> StructLayoutTracker<'a> { } pub fn requires_explicit_align(&self, layout: Layout) -> bool { - self.max_field_align < layout.align && - layout.align <= self.ctx.target_pointer_size() + 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 { |