Skip to content

Commit a8f4bc9

Browse files
author
bors-servo
authored
Auto merge of #1001 - aeleos:master, r=fitzgen
Ensure all derive analyses check array limit on bitfields Fixes #982 r? @fitzgen
2 parents 4842973 + 4111a46 commit a8f4bc9

File tree

7 files changed

+67
-0
lines changed

7 files changed

+67
-0
lines changed

src/ir/analysis/derive_copy.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use ir::derive::CanTriviallyDeriveCopy;
99
use ir::item::IsOpaque;
1010
use ir::template::TemplateParameters;
1111
use ir::traversal::EdgeKind;
12+
use ir::ty::RUST_DERIVE_IN_ARRAY_LIMIT;
1213
use ir::ty::TypeKind;
1314
use std::collections::HashMap;
1415
use std::collections::HashSet;
@@ -266,6 +267,14 @@ impl<'ctx> MonotoneFramework for CannotDeriveCopy<'ctx> {
266267
self.is_not_copy(data.ty())
267268
}
268269
Field::Bitfields(ref bfu) => {
270+
if bfu.layout().align > RUST_DERIVE_IN_ARRAY_LIMIT {
271+
trace!(
272+
" we cannot derive Copy for a bitfield larger then \
273+
the limit"
274+
);
275+
return true;
276+
}
277+
269278
bfu.bitfields().iter().any(|b| {
270279
self.is_not_copy(b.ty())
271280
})

src/ir/analysis/derive_debug.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,14 @@ impl<'ctx> MonotoneFramework for CannotDeriveDebug<'ctx> {
268268
self.is_not_debug(data.ty())
269269
}
270270
Field::Bitfields(ref bfu) => {
271+
if bfu.layout().align > RUST_DERIVE_IN_ARRAY_LIMIT {
272+
trace!(
273+
" we cannot derive Debug for a bitfield larger then \
274+
the limit"
275+
);
276+
return true;
277+
}
278+
271279
bfu.bitfields().iter().any(|b| {
272280
self.is_not_debug(b.ty())
273281
})

src/ir/analysis/derive_default.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,14 @@ impl<'ctx> MonotoneFramework for CannotDeriveDefault<'ctx> {
308308
self.is_not_default(data.ty())
309309
}
310310
Field::Bitfields(ref bfu) => {
311+
if bfu.layout().align > RUST_DERIVE_IN_ARRAY_LIMIT {
312+
trace!(
313+
" we cannot derive Default for a bitfield larger then \
314+
the limit"
315+
);
316+
return true;
317+
}
318+
311319
bfu.bitfields().iter().any(|b| {
312320
!self.ctx.whitelisted_items().contains(
313321
&b.ty(),

src/ir/analysis/derive_hash.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,14 @@ impl<'ctx> MonotoneFramework for CannotDeriveHash<'ctx> {
283283
self.cannot_derive_hash.contains(&data.ty())
284284
}
285285
Field::Bitfields(ref bfu) => {
286+
if bfu.layout().align > RUST_DERIVE_IN_ARRAY_LIMIT {
287+
trace!(
288+
" we cannot derive Hash for a bitfield larger then \
289+
the limit"
290+
);
291+
return true;
292+
}
293+
286294
bfu.bitfields().iter().any(|b| {
287295
!self.ctx.whitelisted_items().contains(
288296
&b.ty(),

src/ir/analysis/derive_partial_eq_or_partial_ord.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,14 @@ impl<'ctx> MonotoneFramework for CannotDerivePartialEqOrPartialOrd<'ctx> {
292292
)
293293
}
294294
Field::Bitfields(ref bfu) => {
295+
if bfu.layout().align > RUST_DERIVE_IN_ARRAY_LIMIT {
296+
trace!(
297+
" we cannot derive PartialEq for a bitfield larger then \
298+
the limit"
299+
);
300+
return true;
301+
}
302+
295303
bfu.bitfields().iter().any(|b| {
296304
!self.ctx.whitelisted_items().contains(
297305
&b.ty(),
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
4+
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
5+
6+
7+
#[repr(C)]
8+
pub struct _bindgen_ty_1 {
9+
pub _bitfield_1: [u8; 128usize],
10+
pub __bindgen_align: [u64; 0usize],
11+
}
12+
impl Default for _bindgen_ty_1 {
13+
fn default() -> Self {
14+
unsafe { ::std::mem::zeroed() }
15+
}
16+
}
17+
extern "C" {
18+
#[link_name = "a"]
19+
pub static mut a: _bindgen_ty_1;
20+
}
21+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// bindgen-flags: --no-layout-tests
2+
3+
struct {
4+
unsigned : 632;
5+
} a;

0 commit comments

Comments
 (0)