Skip to content

Commit 2930a85

Browse files
author
bors-servo
authored
Auto merge of #1059 - aeleos:master, r=fitzgen
Remove early anonymous bitfield filtering and consolidate name method This PR is some changes to early bitfield filtering to help fix (#1007) This does not close (#1007), but allows for checking if the bitfield is too large during a later stage. @fitzgen r?
2 parents 4e74c39 + a1ee87f commit 2930a85

File tree

5 files changed

+30
-27
lines changed

5 files changed

+30
-27
lines changed

src/codegen/impl_debug.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,14 @@ impl<'a> ImplDebug<'a> for BitfieldUnit {
9595
if i > 0 {
9696
format_string.push_str(", ");
9797
}
98-
format_string.push_str(&format!("{} : {{:?}}", bu.name()));
99-
let name_ident = ctx.rust_ident_raw(bu.name());
100-
tokens.push(quote! {
101-
self.#name_ident ()
102-
});
98+
99+
if let Some(name) = bu.name() {
100+
format_string.push_str(&format!("{} : {{:?}}", name));
101+
let name_ident = ctx.rust_ident_raw(name);
102+
tokens.push(quote! {
103+
self.#name_ident ()
104+
});
105+
}
103106
}
104107

105108
Some((format_string, tokens))

src/codegen/impl_partialeq.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ pub fn gen_partialeq_impl(
5151
tokens.push(gen_field(ctx, ty_item, name));
5252
}
5353
Field::Bitfields(ref bu) => for bitfield in bu.bitfields() {
54-
let name_ident = ctx.rust_ident_raw(bitfield.name());
55-
tokens.push(quote! {
56-
self.#name_ident () == other.#name_ident ()
57-
});
54+
if let Some(name) = bitfield.name() {
55+
let name_ident = ctx.rust_ident_raw(name);
56+
tokens.push(quote! {
57+
self.#name_ident () == other.#name_ident ()
58+
});
59+
}
5860
},
5961
}
6062
}

src/codegen/mod.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,10 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit {
11851185
let mut ctor_impl = quote! { 0 };
11861186

11871187
for bf in self.bitfields() {
1188+
// Codegen not allowed for anonymous bitfields
1189+
if bf.name().is_none() {
1190+
continue;
1191+
}
11881192
bf.codegen(
11891193
ctx,
11901194
fields_should_be_private,
@@ -1198,7 +1202,7 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit {
11981202
(&unit_field_name, unit_field_int_ty.clone()),
11991203
);
12001204

1201-
let param_name = bitfield_getter_name(ctx, parent, bf.name());
1205+
let param_name = bitfield_getter_name(ctx, parent, bf.name().unwrap());
12021206
let bitfield_ty_item = ctx.resolve_item(bf.ty());
12031207
let bitfield_ty = bitfield_ty_item.expect_type();
12041208
let bitfield_ty =
@@ -1307,9 +1311,11 @@ impl<'a> FieldCodegen<'a> for Bitfield {
13071311
F: Extend<quote::Tokens>,
13081312
M: Extend<quote::Tokens>,
13091313
{
1314+
// Should never be called with name() as None, as codegen can't be done
1315+
// on an anonymous bitfield
13101316
let prefix = ctx.trait_prefix();
1311-
let getter_name = bitfield_getter_name(ctx, parent, self.name());
1312-
let setter_name = bitfield_setter_name(ctx, parent, self.name());
1317+
let getter_name = bitfield_getter_name(ctx, parent, self.name().unwrap());
1318+
let setter_name = bitfield_setter_name(ctx, parent, self.name().unwrap());
13131319
let unit_field_ident = quote::Ident::new(unit_field_name);
13141320

13151321
let bitfield_ty_item = ctx.resolve_item(self.ty());

src/ir/comp.rs

+7-14
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ impl DotAttributes for Bitfield {
276276
writeln!(
277277
out,
278278
"<tr><td>{} : {}</td><td>{:?}</td></tr>",
279-
self.name(),
279+
self.name().unwrap_or("(anonymous)"),
280280
self.width(),
281281
self.ty()
282282
)
@@ -298,7 +298,6 @@ impl Bitfield {
298298
/// Construct a new bitfield.
299299
fn new(offset_into_unit: usize, raw: RawField) -> Bitfield {
300300
assert!(raw.bitfield().is_some());
301-
assert!(raw.name().is_some());
302301

303302
Bitfield {
304303
offset_into_unit: offset_into_unit,
@@ -332,11 +331,6 @@ impl Bitfield {
332331
pub fn width(&self) -> u32 {
333332
self.data.bitfield().unwrap()
334333
}
335-
336-
/// Get the name of this bitfield.
337-
pub fn name(&self) -> &str {
338-
self.data.name().unwrap()
339-
}
340334
}
341335

342336
impl FieldMethods for Bitfield {
@@ -581,13 +575,12 @@ fn bitfields_to_allocation_units<E, I>(
581575
}
582576
}
583577

584-
// Only keep named bitfields around. Unnamed bitfields (with > 0
585-
// bitsize) are used for padding. Because the `Bitfield` struct stores
586-
// the bit-offset into its allocation unit where its bits begin, we
587-
// don't need any padding bits hereafter.
588-
if bitfield.name().is_some() {
589-
bitfields_in_unit.push(Bitfield::new(offset, bitfield));
590-
}
578+
// Always keep all bitfields around. While unnamed bitifields are used
579+
// for padding (and usually not needed hereafter), large unnamed
580+
// bitfields over their types size cause weird allocation size behavior from clang.
581+
// Therefore, all bitfields needed to be kept around in order to check for this
582+
// and make the struct opaque in this case
583+
bitfields_in_unit.push(Bitfield::new(offset, bitfield));
591584

592585
max_align = cmp::max(max_align, bitfield_align);
593586

tests/expectations/tests/bitfield_large_overflow.rs

-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,3 @@ extern "C" {
1818
#[link_name = "a"]
1919
pub static mut a: _bindgen_ty_1;
2020
}
21-

0 commit comments

Comments
 (0)