summaryrefslogtreecommitdiff
path: root/src/codegen/mod.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2018-03-13 07:25:45 -0400
committerGitHub <noreply@github.com>2018-03-13 07:25:45 -0400
commit9a0edb86548dca98cce6aad9025f5a8fc92a8522 (patch)
tree5cd215a00f4ac8096ad0c3291ca664881c72e923 /src/codegen/mod.rs
parent60c3d336760d3b10c637551a2a8beb0f9a588315 (diff)
parent853ae4d96c7c1b33965fabd822ee9a7201847597 (diff)
Auto merge of #1271 - emilio:repr-align, r=xidorn
codegen: Support repr(align) Fixes #917.
Diffstat (limited to 'src/codegen/mod.rs')
-rw-r--r--src/codegen/mod.rs24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index 1801520a..a6ab3997 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");
@@ -1655,7 +1671,7 @@ impl CodeGenerator for CompInfo {
if item.can_derive_copy(ctx) && !item.annotations().disallow_copy() {
derives.push("Copy");
- if ctx.options().rust_features().builtin_clone_impls() ||
+ if ctx.options().rust_features().builtin_clone_impls ||
used_template_params.is_some()
{
// FIXME: This requires extra logic if you have a big array in a
@@ -1996,7 +2012,7 @@ impl MethodCodegen for Method {
_ => panic!("How in the world?"),
};
- if let (Abi::ThisCall, false) = (signature.abi(), ctx.options().rust_features().thiscall_abi()) {
+ if let (Abi::ThisCall, false) = (signature.abi(), ctx.options().rust_features().thiscall_abi) {
return;
}
@@ -3167,7 +3183,7 @@ impl TryToRustTy for FunctionSig {
let abi = self.abi();
match abi {
- Abi::ThisCall if !ctx.options().rust_features().thiscall_abi() => {
+ Abi::ThisCall if !ctx.options().rust_features().thiscall_abi => {
warn!("Skipping function with thiscall ABI that isn't supported by the configured Rust target");
Ok(quote::Tokens::new())
}
@@ -3264,7 +3280,7 @@ impl CodeGenerator for Function {
}
let abi = match signature.abi() {
- Abi::ThisCall if !ctx.options().rust_features().thiscall_abi() => {
+ Abi::ThisCall if !ctx.options().rust_features().thiscall_abi => {
warn!("Skipping function with thiscall ABI that isn't supported by the configured Rust target");
return;
}