diff options
author | Emilio Cobos Álvarez <emilio@crisal.io> | 2020-02-02 20:56:25 +0100 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2020-02-02 23:10:49 +0100 |
commit | e951825e850dbb527e5de255a6500766dad61994 (patch) | |
tree | 35e2caee28f449cdbb56819bf48fecb3526b5154 /src/codegen/mod.rs | |
parent | 2929af608fdc18c3970e9390bc7d2079e745d752 (diff) |
ir: codegen: Handle too large bitfield units.
By not generating various code for it.
In the future, we could improve on this by splitting contiguous bitfield units,
if needed, so that we can implement them without dealing with rust array derive
limits.
Fixes #1718
Diffstat (limited to 'src/codegen/mod.rs')
-rw-r--r-- | src/codegen/mod.rs | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 5ac8dc11..ab62b135 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -1310,23 +1310,26 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { F: Extend<proc_macro2::TokenStream>, M: Extend<proc_macro2::TokenStream>, { + use ir::ty::RUST_DERIVE_IN_ARRAY_LIMIT; + result.saw_bitfield_unit(); + let layout = self.layout(); + let unit_field_ty = helpers::bitfield_unit(ctx, layout); let field_ty = { - let ty = helpers::bitfield_unit(ctx, self.layout()); if parent.is_union() && !parent.can_be_rust_union(ctx) { result.saw_bindgen_union(); if ctx.options().enable_cxx_namespaces { quote! { - root::__BindgenUnionField<#ty> + root::__BindgenUnionField<#unit_field_ty> } } else { quote! { - __BindgenUnionField<#ty> + __BindgenUnionField<#unit_field_ty> } } } else { - ty + unit_field_ty.clone() } }; @@ -1338,12 +1341,13 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { }; fields.extend(Some(field)); - let unit_field_ty = helpers::bitfield_unit(ctx, self.layout()); - let ctor_name = self.ctor_name(); let mut ctor_params = vec![]; let mut ctor_impl = quote! {}; - let mut generate_ctor = true; + + // We cannot generate any constructor if the underlying storage can't + // implement AsRef<[u8]> / AsMut<[u8]> / etc. + let mut generate_ctor = layout.size <= RUST_DERIVE_IN_ARRAY_LIMIT; for bf in self.bitfields() { // Codegen not allowed for anonymous bitfields @@ -1351,6 +1355,10 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { continue; } + if layout.size > RUST_DERIVE_IN_ARRAY_LIMIT { + continue; + } + let mut bitfield_representable_as_int = true; bf.codegen( @@ -1395,7 +1403,7 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { })); } - struct_layout.saw_bitfield_unit(self.layout()); + struct_layout.saw_bitfield_unit(layout); } } |