summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ir/analysis/derive_copy.rs9
-rw-r--r--src/ir/analysis/derive_debug.rs8
-rw-r--r--src/ir/analysis/derive_default.rs8
-rw-r--r--src/ir/analysis/derive_hash.rs8
-rw-r--r--src/ir/analysis/derive_partial_eq_or_partial_ord.rs8
-rw-r--r--tests/expectations/tests/bitfield_large_overflow.rs21
-rw-r--r--tests/headers/bitfield_large_overflow.hpp5
7 files changed, 67 insertions, 0 deletions
diff --git a/src/ir/analysis/derive_copy.rs b/src/ir/analysis/derive_copy.rs
index ef01c65a..264d227a 100644
--- a/src/ir/analysis/derive_copy.rs
+++ b/src/ir/analysis/derive_copy.rs
@@ -9,6 +9,7 @@ use ir::derive::CanTriviallyDeriveCopy;
use ir::item::IsOpaque;
use ir::template::TemplateParameters;
use ir::traversal::EdgeKind;
+use ir::ty::RUST_DERIVE_IN_ARRAY_LIMIT;
use ir::ty::TypeKind;
use std::collections::HashMap;
use std::collections::HashSet;
@@ -266,6 +267,14 @@ impl<'ctx> MonotoneFramework for CannotDeriveCopy<'ctx> {
self.is_not_copy(data.ty())
}
Field::Bitfields(ref bfu) => {
+ if bfu.layout().align > RUST_DERIVE_IN_ARRAY_LIMIT {
+ trace!(
+ " we cannot derive Copy for a bitfield larger then \
+ the limit"
+ );
+ return true;
+ }
+
bfu.bitfields().iter().any(|b| {
self.is_not_copy(b.ty())
})
diff --git a/src/ir/analysis/derive_debug.rs b/src/ir/analysis/derive_debug.rs
index 2bfaff71..7df745c9 100644
--- a/src/ir/analysis/derive_debug.rs
+++ b/src/ir/analysis/derive_debug.rs
@@ -268,6 +268,14 @@ impl<'ctx> MonotoneFramework for CannotDeriveDebug<'ctx> {
self.is_not_debug(data.ty())
}
Field::Bitfields(ref bfu) => {
+ if bfu.layout().align > RUST_DERIVE_IN_ARRAY_LIMIT {
+ trace!(
+ " we cannot derive Debug for a bitfield larger then \
+ the limit"
+ );
+ return true;
+ }
+
bfu.bitfields().iter().any(|b| {
self.is_not_debug(b.ty())
})
diff --git a/src/ir/analysis/derive_default.rs b/src/ir/analysis/derive_default.rs
index 96805863..7acbe04a 100644
--- a/src/ir/analysis/derive_default.rs
+++ b/src/ir/analysis/derive_default.rs
@@ -308,6 +308,14 @@ impl<'ctx> MonotoneFramework for CannotDeriveDefault<'ctx> {
self.is_not_default(data.ty())
}
Field::Bitfields(ref bfu) => {
+ if bfu.layout().align > RUST_DERIVE_IN_ARRAY_LIMIT {
+ trace!(
+ " we cannot derive Default for a bitfield larger then \
+ the limit"
+ );
+ return true;
+ }
+
bfu.bitfields().iter().any(|b| {
!self.ctx.whitelisted_items().contains(
&b.ty(),
diff --git a/src/ir/analysis/derive_hash.rs b/src/ir/analysis/derive_hash.rs
index 80ea0abf..5313cae3 100644
--- a/src/ir/analysis/derive_hash.rs
+++ b/src/ir/analysis/derive_hash.rs
@@ -283,6 +283,14 @@ impl<'ctx> MonotoneFramework for CannotDeriveHash<'ctx> {
self.cannot_derive_hash.contains(&data.ty())
}
Field::Bitfields(ref bfu) => {
+ if bfu.layout().align > RUST_DERIVE_IN_ARRAY_LIMIT {
+ trace!(
+ " we cannot derive Hash for a bitfield larger then \
+ the limit"
+ );
+ return true;
+ }
+
bfu.bitfields().iter().any(|b| {
!self.ctx.whitelisted_items().contains(
&b.ty(),
diff --git a/src/ir/analysis/derive_partial_eq_or_partial_ord.rs b/src/ir/analysis/derive_partial_eq_or_partial_ord.rs
index 1d4a5939..1c3ab059 100644
--- a/src/ir/analysis/derive_partial_eq_or_partial_ord.rs
+++ b/src/ir/analysis/derive_partial_eq_or_partial_ord.rs
@@ -292,6 +292,14 @@ impl<'ctx> MonotoneFramework for CannotDerivePartialEqOrPartialOrd<'ctx> {
)
}
Field::Bitfields(ref bfu) => {
+ if bfu.layout().align > RUST_DERIVE_IN_ARRAY_LIMIT {
+ trace!(
+ " we cannot derive PartialEq for a bitfield larger then \
+ the limit"
+ );
+ return true;
+ }
+
bfu.bitfields().iter().any(|b| {
!self.ctx.whitelisted_items().contains(
&b.ty(),
diff --git a/tests/expectations/tests/bitfield_large_overflow.rs b/tests/expectations/tests/bitfield_large_overflow.rs
new file mode 100644
index 00000000..523570e4
--- /dev/null
+++ b/tests/expectations/tests/bitfield_large_overflow.rs
@@ -0,0 +1,21 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+#[repr(C)]
+pub struct _bindgen_ty_1 {
+ pub _bitfield_1: [u8; 128usize],
+ pub __bindgen_align: [u64; 0usize],
+}
+impl Default for _bindgen_ty_1 {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
+}
+extern "C" {
+ #[link_name = "a"]
+ pub static mut a: _bindgen_ty_1;
+}
+
diff --git a/tests/headers/bitfield_large_overflow.hpp b/tests/headers/bitfield_large_overflow.hpp
new file mode 100644
index 00000000..227829b8
--- /dev/null
+++ b/tests/headers/bitfield_large_overflow.hpp
@@ -0,0 +1,5 @@
+// bindgen-flags: --no-layout-tests
+
+struct {
+ unsigned : 632;
+} a;