Skip to content

Commit e99a9fc

Browse files
author
Dan Robertson
committed
Allow zero sized unions to be defined
A union may be defined in C that contains only zero sized types. We should in turn generate a rust union in this case.
1 parent b7b501f commit e99a9fc

3 files changed

Lines changed: 164 additions & 1 deletion

File tree

bindgen-tests/tests/expectations/tests/struct_with_anon_union_of_array_members.rs

Lines changed: 148 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// bindgen-flags: --default-non-copy-union-style manually_drop
2+
struct bpf_array {
3+
union {
4+
struct {
5+
struct {} __empty_value1;
6+
char value1[];
7+
};
8+
struct {
9+
struct {} __empty_value2;
10+
char value2[];
11+
};
12+
};
13+
};

bindgen/ir/comp.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1750,7 +1750,9 @@ impl CompInfo {
17501750
return (false, false);
17511751
}
17521752

1753-
if layout.is_some_and(|l| l.size == 0) {
1753+
if layout.is_some_and(|l| l.size == 0) &&
1754+
union_style != NonCopyUnionStyle::ManuallyDrop
1755+
{
17541756
return (false, false);
17551757
}
17561758

0 commit comments

Comments
 (0)