summaryrefslogtreecommitdiff
path: root/src
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
parent60c3d336760d3b10c637551a2a8beb0f9a588315 (diff)
codegen: support repr(align).
Fixes #917
Diffstat (limited to 'src')
-rw-r--r--src/codegen/mod.rs16
-rw-r--r--src/features.rs8
2 files changed, 24 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");
diff --git a/src/features.rs b/src/features.rs
index d4fbd928..fe4f8453 100644
--- a/src/features.rs
+++ b/src/features.rs
@@ -92,6 +92,8 @@ macro_rules! rust_target_base {
=> Stable_1_19 => 1.19;
/// Rust stable 1.21
=> Stable_1_21 => 1.21;
+ /// Rust stable 1.24
+ => Stable_1_24 => 1.24;
/// Nightly rust
=> Nightly => nightly;
);
@@ -144,6 +146,8 @@ rust_feature_def!(
=> thiscall_abi;
/// builtin impls for `Clone` ([PR](https://github.com/rust-lang/rust/pull/43690))
=> builtin_clone_impls;
+ /// repr(align) https://github.com/rust-lang/rust/pull/47006
+ => repr_align;
);
impl From<RustTarget> for RustFeatures {
@@ -158,6 +162,10 @@ impl From<RustTarget> for RustFeatures {
features.builtin_clone_impls = true;
}
+ if rust_target >= RustTarget::Stable_1_24 {
+ features.repr_align = true;
+ }
+
if rust_target >= RustTarget::Nightly {
features.thiscall_abi = true;
}