summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/codegen/impl_partialeq.rs2
-rw-r--r--src/codegen/mod.rs24
-rw-r--r--src/features.rs23
-rw-r--r--src/ir/analysis/derive_copy.rs2
-rw-r--r--src/ir/analysis/derive_debug.rs4
-rw-r--r--src/ir/analysis/derive_default.rs4
-rw-r--r--src/ir/analysis/derive_hash.rs4
-rw-r--r--src/ir/analysis/derive_partialeq_or_partialord.rs4
-rw-r--r--src/ir/comp.rs2
-rw-r--r--src/lib.rs6
10 files changed, 50 insertions, 25 deletions
diff --git a/src/codegen/impl_partialeq.rs b/src/codegen/impl_partialeq.rs
index 02783808..31c2c979 100644
--- a/src/codegen/impl_partialeq.rs
+++ b/src/codegen/impl_partialeq.rs
@@ -20,7 +20,7 @@ pub fn gen_partialeq_impl(
&self._bindgen_opaque_blob[..] == &other._bindgen_opaque_blob[..]
});
} else if comp_info.kind() == CompKind::Union {
- assert!(!ctx.options().rust_features().untagged_union());
+ assert!(!ctx.options().rust_features().untagged_union);
tokens.push(quote! {
&self.bindgen_union_field[..] == &other.bindgen_union_field[..]
});
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;
}
diff --git a/src/features.rs b/src/features.rs
index d4fbd928..866d7126 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.25
+ => Stable_1_25 => 1.25;
/// Nightly rust
=> Nightly => nightly;
);
@@ -111,7 +113,10 @@ macro_rules! rust_feature_def {
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct RustFeatures {
$(
- $feature: bool,
+ $(
+ #[$attr]
+ )*
+ pub $feature: bool,
)*
}
@@ -124,15 +129,6 @@ macro_rules! rust_feature_def {
)*
}
}
-
- $(
- $(
- #[$attr]
- )*
- pub fn $feature(&self) -> bool {
- self.$feature
- }
- )*
}
}
}
@@ -144,6 +140,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 +156,10 @@ impl From<RustTarget> for RustFeatures {
features.builtin_clone_impls = true;
}
+ if rust_target >= RustTarget::Stable_1_25 {
+ features.repr_align = true;
+ }
+
if rust_target >= RustTarget::Nightly {
features.thiscall_abi = true;
}
@@ -189,6 +191,7 @@ mod test {
test_target("1.0", RustTarget::Stable_1_0);
test_target("1.19", RustTarget::Stable_1_19);
test_target("1.21", RustTarget::Stable_1_21);
+ test_target("1.25", RustTarget::Stable_1_25);
test_target("nightly", RustTarget::Nightly);
}
}
diff --git a/src/ir/analysis/derive_copy.rs b/src/ir/analysis/derive_copy.rs
index 94d457d5..69725ead 100644
--- a/src/ir/analysis/derive_copy.rs
+++ b/src/ir/analysis/derive_copy.rs
@@ -234,7 +234,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveCopy<'ctx> {
}
if info.kind() == CompKind::Union {
- if !self.ctx.options().rust_features().untagged_union() {
+ if !self.ctx.options().rust_features().untagged_union {
// NOTE: If there's no template parameters we can derive
// copy unconditionally, since arrays are magical for
// rustc, and __BindgenUnionField always implements
diff --git a/src/ir/analysis/derive_debug.rs b/src/ir/analysis/derive_debug.rs
index a1743ae9..b191d37d 100644
--- a/src/ir/analysis/derive_debug.rs
+++ b/src/ir/analysis/derive_debug.rs
@@ -150,7 +150,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveDebug<'ctx> {
});
return if layout_can_derive &&
!(ty.is_union() &&
- self.ctx.options().rust_features().untagged_union()) {
+ self.ctx.options().rust_features().untagged_union) {
trace!(" we can trivially derive Debug for the layout");
ConstrainResult::Same
} else {
@@ -235,7 +235,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveDebug<'ctx> {
);
if info.kind() == CompKind::Union {
- if self.ctx.options().rust_features().untagged_union() {
+ if self.ctx.options().rust_features().untagged_union {
trace!(" cannot derive Debug for Rust unions");
return self.insert(id);
}
diff --git a/src/ir/analysis/derive_default.rs b/src/ir/analysis/derive_default.rs
index 2c79a437..e319166d 100644
--- a/src/ir/analysis/derive_default.rs
+++ b/src/ir/analysis/derive_default.rs
@@ -177,7 +177,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveDefault<'ctx> {
});
return if layout_can_derive &&
!(ty.is_union() &&
- self.ctx.options().rust_features().untagged_union()) {
+ self.ctx.options().rust_features().untagged_union) {
trace!(" we can trivially derive Default for the layout");
ConstrainResult::Same
} else {
@@ -271,7 +271,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveDefault<'ctx> {
}
if info.kind() == CompKind::Union {
- if self.ctx.options().rust_features().untagged_union() {
+ if self.ctx.options().rust_features().untagged_union {
trace!(" cannot derive Default for Rust unions");
return self.insert(id);
}
diff --git a/src/ir/analysis/derive_hash.rs b/src/ir/analysis/derive_hash.rs
index 3fc31b39..c23a891e 100644
--- a/src/ir/analysis/derive_hash.rs
+++ b/src/ir/analysis/derive_hash.rs
@@ -137,7 +137,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveHash<'ctx> {
});
return if layout_can_derive &&
!(ty.is_union() &&
- self.ctx.options().rust_features().untagged_union()) {
+ self.ctx.options().rust_features().untagged_union) {
trace!(" we can trivially derive Hash for the layout");
ConstrainResult::Same
} else {
@@ -257,7 +257,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveHash<'ctx> {
}
if info.kind() == CompKind::Union {
- if self.ctx.options().rust_features().untagged_union() {
+ if self.ctx.options().rust_features().untagged_union {
trace!(" cannot derive Hash for Rust unions");
return self.insert(id);
}
diff --git a/src/ir/analysis/derive_partialeq_or_partialord.rs b/src/ir/analysis/derive_partialeq_or_partialord.rs
index 2641d2b3..cebdceef 100644
--- a/src/ir/analysis/derive_partialeq_or_partialord.rs
+++ b/src/ir/analysis/derive_partialeq_or_partialord.rs
@@ -119,7 +119,7 @@ impl<'ctx> CannotDerivePartialEqOrPartialOrd<'ctx> {
trace!("ty: {:?}", ty);
if item.is_opaque(self.ctx, &()) {
if ty.is_union()
- && self.ctx.options().rust_features().untagged_union()
+ && self.ctx.options().rust_features().untagged_union
{
trace!(
" cannot derive `PartialEq`/`PartialOrd` for Rust unions"
@@ -242,7 +242,7 @@ impl<'ctx> CannotDerivePartialEqOrPartialOrd<'ctx> {
}
if info.kind() == CompKind::Union {
- if self.ctx.options().rust_features().untagged_union() {
+ if self.ctx.options().rust_features().untagged_union {
trace!(
" cannot derive `PartialEq`/`PartialOrd` for Rust unions"
);
diff --git a/src/ir/comp.rs b/src/ir/comp.rs
index 24909cb5..131851fd 100644
--- a/src/ir/comp.rs
+++ b/src/ir/comp.rs
@@ -1543,7 +1543,7 @@ impl CompInfo {
/// 1. Current RustTarget allows for `untagged_union`
/// 2. Each field can derive `Copy`
pub fn can_be_rust_union(&self, ctx: &BindgenContext) -> bool {
- if !ctx.options().rust_features().untagged_union() {
+ if !ctx.options().rust_features().untagged_union {
return false;
}
diff --git a/src/lib.rs b/src/lib.rs
index db58f6f4..6346ff80 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -600,6 +600,12 @@ impl Builder {
self
}
+ /// Disable support for native Rust unions, if supported.
+ pub fn disable_untagged_union(mut self) -> Self {
+ self.options.rust_features.untagged_union = false;
+ self
+ }
+
/// Set the output graphviz file.
pub fn emit_ir_graphviz<T: Into<String>>(mut self, path: T) -> Builder {
let path = path.into();