Skip to content

Commit 308d5f6

Browse files
committed
Fixes alignment errors with new Rust union type
This fix creates a new private field with the required aligned size. This new private field ensures that the union has the required size.
1 parent 8c71eed commit 308d5f6

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/codegen/mod.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,14 +1612,20 @@ impl CodeGenerator for CompInfo {
16121612
);
16131613
}
16141614

1615-
if is_union && !self.can_be_rust_union(ctx) {
1615+
if is_union {
16161616
let layout = layout.expect("Unable to get layout information?");
16171617
let ty = BlobTyBuilder::new(layout).build();
1618-
let field = StructFieldBuilder::named("bindgen_union_field")
1619-
.pub_()
1620-
.build_ty(ty);
1618+
1619+
let field = if self.can_be_rust_union(ctx) {
1620+
StructFieldBuilder::named("_bindgen_union_align")
1621+
.build_ty(ty)
1622+
} else {
1623+
struct_layout.saw_union(layout);
16211624

1622-
struct_layout.saw_union(layout);
1625+
StructFieldBuilder::named("bindgen_union_field")
1626+
.pub_()
1627+
.build_ty(ty)
1628+
};
16231629

16241630
fields.push(field);
16251631
}

0 commit comments

Comments
 (0)