summaryrefslogtreecommitdiff
path: root/src/codegen/mod.rs
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <emilio@crisal.io>2018-03-10 07:06:36 +0100
committerEmilio Cobos Álvarez <emilio@crisal.io>2018-03-13 12:15:47 +0100
commit96b26b308dbfb5acde0ede785dcbb7d276ef98f2 (patch)
treeadbee3a30bc85908ab21f7903e4750f76bf4fb9a /src/codegen/mod.rs
parent60c3d336760d3b10c637551a2a8beb0f9a588315 (diff)
codegen: support repr(align).
Fixes #917
Diffstat (limited to 'src/codegen/mod.rs')
-rw-r--r--src/codegen/mod.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index 1801520a..950708a0 100644
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -1527,6 +1527,7 @@ impl CodeGenerator for CompInfo {
});
}
+ let mut explicit_align = None;
if is_opaque {
// Opaque item should not have generated methods, fields.
debug_assert!(fields.is_empty());
@@ -1534,6 +1535,8 @@ impl CodeGenerator for CompInfo {
match layout {
Some(l) => {
+ explicit_align = Some(l.align);
+
let ty = helpers::blob(l);
fields.push(quote! {
pub _bindgen_opaque_blob: #ty ,
@@ -1555,6 +1558,7 @@ impl CodeGenerator for CompInfo {
if layout.align == 1 {
packed = true;
} else {
+ explicit_align = Some(layout.align);
let ty = helpers::blob(Layout::new(0, layout.align));
fields.push(quote! {
pub __bindgen_align: #ty ,
@@ -1637,6 +1641,18 @@ impl CodeGenerator for CompInfo {
attributes.push(attributes::repr("C"));
}
+ if ctx.options().rust_features().repr_align() {
+ if let Some(explicit) = explicit_align {
+ // Ensure that the struct has the correct alignment even in
+ // presence of alignas.
+ let explicit = helpers::ast_ty::int_expr(explicit as i64);
+ attributes.push(quote! {
+ #[repr(align(#explicit))]
+ });
+ }
+ }
+
+
let mut derives = vec![];
if item.can_derive_debug(ctx) {
derives.push("Debug");