Skip to content

Fix zero-length bitfield handling in the P/Invoke generator#817

Merged
tannergooding merged 2 commits into
dotnet:mainfrom
tannergooding:tannergooding-v22-zero-length-bitfield
Jul 17, 2026
Merged

Fix zero-length bitfield handling in the P/Invoke generator#817
tannergooding merged 2 commits into
dotnet:mainfrom
tannergooding:tannergooding-v22-zero-length-bitfield

Conversation

@tannergooding

Copy link
Copy Markdown
Member

A zero-length bitfield (int : 0;) is a layout-only marker: it names no storage and forces the next bitfield into a fresh storage unit. The generator previously ran it through the normal bitfield path, which emitted a bogus 0-length region and packed the following bitfield into the same backing field.

GetBitfieldDescs and the VisitRecordDecl emit loop now skip zero-length bitfields via FieldDecl.IsZeroLengthBitField and reset the running size/bit counters, so the next bitfield lands in a new storage unit.


Adds ZeroLengthBitfieldTest (with GenerateNativeBitfieldAttribute) covering o0_b0_1 -> _bitfield1 and o4_b0_1 -> _bitfield2 across a : 0 boundary. Full generator baseline suite green (4085), 0 warnings.

Note

Authored with Copilot.

tannergooding and others added 2 commits July 16, 2026 23:09
A zero-length bitfield (`int : 0;`) is a layout-only marker that names no
storage and forces the next bitfield into a fresh storage unit. The generator
previously ran it through the normal bitfield path, emitting a bogus 0-length
region and packing the following bitfield into the same backing field. Skip it
via FieldDecl.IsZeroLengthBitField and reset the run so the next bitfield gets a
new storage unit.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@tannergooding
tannergooding merged commit dfdf9ba into dotnet:main Jul 17, 2026
12 checks passed
@tannergooding
tannergooding deleted the tannergooding-v22-zero-length-bitfield branch July 17, 2026 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant