summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock43
-rw-r--r--Cargo.toml4
-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
-rw-r--r--tests/expectations/tests/repr-align.rs67
-rw-r--r--tests/headers/repr-align.hpp11
14 files changed, 154 insertions, 46 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 637bc3eb..9fbb7087 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -17,17 +17,17 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "libc 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "bindgen"
-version = "0.33.1"
+version = "0.34.0"
dependencies = [
"cexpr 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "clang-sys 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "clang-sys 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)",
"clap 2.24.2 (registry+https://github.com/rust-lang/crates.io-index)",
"diff 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -46,6 +46,11 @@ version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
+name = "cc"
+version = "1.0.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
name = "cexpr"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -69,12 +74,12 @@ dependencies = [
[[package]]
name = "clang-sys"
-version = "0.21.0"
+version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
- "libc 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
- "libloading 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libloading 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -130,17 +135,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "libc"
-version = "0.2.23"
+version = "0.2.39"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "libloading"
-version = "0.4.3"
+version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cc 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -156,7 +160,7 @@ name = "memchr"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "libc 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -244,7 +248,7 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "libc 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -262,7 +266,7 @@ version = "3.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "libc 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -279,7 +283,7 @@ name = "time"
version = "0.1.39"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "libc 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -322,7 +326,7 @@ name = "which"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "libc 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -367,18 +371,19 @@ dependencies = [
"checksum ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "23ac7c30002a5accbf7e8987d0632fa6de155b7c3d39d0067317a391e00a2ef6"
"checksum atty 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d912da0db7fa85514874458ca3651fe2cddace8d0b0505571dbdcd41ab490159"
"checksum bitflags 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1370e9fc2a6ae53aea8b7a5110edbd08836ed87c88736dfabccade1c2b44bff4"
+"checksum cc 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "fedf677519ac9e865c4ff43ef8f930773b37ed6e6ea61b6b83b400a7b5787f49"
"checksum cexpr 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "393a5f0088efbe41f9d1fcd062f24e83c278608420e62109feb2c8abee07de7d"
"checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de"
"checksum chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7c20ebe0b2b08b0aeddba49c609fe7957ba2e33449882cb186a180bc60682fa9"
-"checksum clang-sys 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5955eab05fa8e6ff2b353753dc73a0608daa36e472a21c69f2eb51f43f593544"
+"checksum clang-sys 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)" = "939a1a34310b120d26eba35c29475933128b0ec58e24b43327f8dbe6036fc538"
"checksum clap 2.24.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6b8f69e518f967224e628896b54e41ff6acfb4dcfefc5076325c36525dac900f"
"checksum diff 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "0a515461b6c8c08419850ced27bc29e86166dcdcde8fbe76f8b1f0589bb49472"
"checksum env_logger 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f15f0b172cb4f52ed5dbf47f774a387cd2315d1bf7894ab5af9b083ae27efa5a"
"checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb"
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
"checksum lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c8f31047daa365f19be14b47c29df4f7c3b581832407daabe6ae77397619237d"
-"checksum libc 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)" = "e7eb6b826bfc1fdea7935d46556250d1799b7fe2d9f7951071f4291710665e3e"
-"checksum libloading 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "fd38073de8f7965d0c17d30546d4bb6da311ab428d1c7a3fc71dff7f9d4979b9"
+"checksum libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)" = "f54263ad99207254cf58b5f701ecb432c717445ea2ee8af387334bdd1a03fdff"
+"checksum libloading 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9c3ad660d7cb8c5822cd83d10897b0f1f1526792737a179e73896152f85b88c2"
"checksum log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "89f010e843f2b1a31dbd316b3b8d443758bc634bed37aabade59c686d644e0a2"
"checksum memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1dbccc0e46f1ea47b9f17e6d67c5a96bd27030519c519c9c91327e31275a47b4"
"checksum nom 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a5b8c256fd9471521bcb84c3cdba98921497f1a331cbc15b8030fc63b82050ce"
diff --git a/Cargo.toml b/Cargo.toml
index 630f197c..d8444ff0 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,7 +13,7 @@ name = "bindgen"
readme = "README.md"
repository = "https://github.com/rust-lang-nursery/rust-bindgen"
documentation = "https://docs.rs/bindgen"
-version = "0.33.1"
+version = "0.34.0"
build = "build.rs"
include = [
@@ -44,7 +44,7 @@ cexpr = "0.2"
cfg-if = "0.1.0"
# This kinda sucks: https://github.com/rust-lang/cargo/issues/1982
clap = "2"
-clang-sys = { version = "0.21.0", features = ["runtime", "clang_3_9"] }
+clang-sys = { version = "0.22.0", features = ["runtime", "clang_3_9"] }
lazy_static = "1"
peeking_take_while = "0.1.2"
quote = "0.3.15"
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 1a948c05..cf1a4f3b 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;
}
@@ -3169,7 +3185,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())
}
@@ -3266,7 +3282,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 12b38257..36378316 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -617,6 +617,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();
diff --git a/tests/expectations/tests/repr-align.rs b/tests/expectations/tests/repr-align.rs
new file mode 100644
index 00000000..1827ca9d
--- /dev/null
+++ b/tests/expectations/tests/repr-align.rs
@@ -0,0 +1,67 @@
+/* automatically generated by rust-bindgen */
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+#![cfg(feature = "nightly")]
+
+#[repr(C)]
+#[repr(align(8))]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct a {
+ pub b: ::std::os::raw::c_int,
+ pub c: ::std::os::raw::c_int,
+ pub __bindgen_align: [u64; 0usize],
+}
+#[test]
+fn bindgen_test_layout_a() {
+ assert_eq!(
+ ::std::mem::size_of::<a>(),
+ 8usize,
+ concat!("Size of: ", stringify!(a))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<a>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(a))
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<a>())).b as *const _ as usize },
+ 0usize,
+ concat!("Offset of field: ", stringify!(a), "::", stringify!(b))
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<a>())).c as *const _ as usize },
+ 4usize,
+ concat!("Offset of field: ", stringify!(a), "::", stringify!(c))
+ );
+}
+#[repr(C)]
+#[repr(align(8))]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct b {
+ pub b: ::std::os::raw::c_int,
+ pub c: ::std::os::raw::c_int,
+ pub __bindgen_align: [u64; 0usize],
+}
+#[test]
+fn bindgen_test_layout_b() {
+ assert_eq!(
+ ::std::mem::size_of::<b>(),
+ 8usize,
+ concat!("Size of: ", stringify!(b))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<b>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(b))
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<b>())).b as *const _ as usize },
+ 0usize,
+ concat!("Offset of field: ", stringify!(b), "::", stringify!(b))
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<b>())).c as *const _ as usize },
+ 4usize,
+ concat!("Offset of field: ", stringify!(b), "::", stringify!(c))
+ );
+}
diff --git a/tests/headers/repr-align.hpp b/tests/headers/repr-align.hpp
new file mode 100644
index 00000000..3347594b
--- /dev/null
+++ b/tests/headers/repr-align.hpp
@@ -0,0 +1,11 @@
+// bindgen-flags: --raw-line '#![cfg(feature = "nightly")]' --rust-target 1.25 -- -std=c++11
+
+struct alignas(8) a {
+ int b;
+ int c;
+};
+
+struct alignas(double) b {
+ int b;
+ int c;
+};