Skip to content

Commit 07b8323

Browse files
author
Benjamin Lerman
committed
Fix union layout when it contains 0 sized array.
Fix #3068
1 parent 20aa65a commit 07b8323

File tree

3 files changed

+78
-1
lines changed

3 files changed

+78
-1
lines changed

Diff for: 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+
};

Diff for: bindgen/codegen/struct_layout.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,11 @@ 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 = cmp::max(self.latest_offset, field_layout.size);
273+
}
270274
self.latest_field_layout = Some(field_layout);
271275
self.max_field_align =
272276
cmp::max(self.max_field_align, field_layout.align);

0 commit comments

Comments
 (0)