Skip to content

Commit

Permalink
Auto merge of #1001 - aeleos:master, r=fitzgen
Browse files Browse the repository at this point in the history
Ensure all derive analyses check array limit on bitfields

Fixes #982

r? @fitzgen
  • Loading branch information
bors-servo authored Sep 20, 2017
2 parents 4842973 + 4111a46 commit a8f4bc9
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/ir/analysis/derive_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
})
Expand Down
8 changes: 8 additions & 0 deletions src/ir/analysis/derive_debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})
Expand Down
8 changes: 8 additions & 0 deletions src/ir/analysis/derive_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
8 changes: 8 additions & 0 deletions src/ir/analysis/derive_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
8 changes: 8 additions & 0 deletions src/ir/analysis/derive_partial_eq_or_partial_ord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
21 changes: 21 additions & 0 deletions tests/expectations/tests/bitfield_large_overflow.rs
Original file line number Diff line number Diff line change
@@ -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;
}

5 changes: 5 additions & 0 deletions tests/headers/bitfield_large_overflow.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// bindgen-flags: --no-layout-tests

struct {
unsigned : 632;
} a;

0 comments on commit a8f4bc9

Please sign in to comment.