Skip to content

Commit a50a2cf

Browse files
Benjamin Lermanemilio
Benjamin Lerman
authored andcommitted
Fix union layout when it contains 0 sized array.
Fix #3068
1 parent 8a3b0ec commit a50a2cf

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

bindgen-tests/tests/expectations/tests/union_with_zero_sized_array.rs

+68
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
union U {
2+
char d0[0];
3+
char d1[1];
4+
char d2[2];
5+
};

bindgen/codegen/struct_layout.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,12 @@ impl<'a> StructLayoutTracker<'a> {
266266
}
267267
};
268268

269-
self.latest_offset += field_layout.size;
269+
if !is_union {
270+
self.latest_offset += field_layout.size;
271+
} else {
272+
self.latest_offset =
273+
cmp::max(self.latest_offset, field_layout.size);
274+
}
270275
self.latest_field_layout = Some(field_layout);
271276
self.max_field_align =
272277
cmp::max(self.max_field_align, field_layout.align);

0 commit comments

Comments
 (0)