mirror of
https://github.com/protocolbuffers/protobuf
synced 2026-08-26 02:23:14 -04:00
### Description This PR fixes the issue where an unused `_hasBits` field is allocated in the generated C# code when the number of presence bits is an exact multiple of 32. **Changes:** - Updated the `has_bit_field_count_` calculation in `MessageGenerator` to use the formula: `(presence_bit_count + 31) / 32`. - This ensures that exactly 1 `int32` is allocated for 32 fields, 2 for 64 fields, etc., instead of over-allocating. **Testing:** - Added `TestPresenceBits` to `unittest_issues.proto` which includes exactly 32 optional fields. - Added a unit test in `Proto3OptionalTest.cs` to assert that exactly one `_hasBits0` field is generated via reflection. Fixes #26391 Closes #26455 PiperOrigin-RevId: 885948073 |
||
|---|---|---|
| .. | ||
| map_unittest_proto3.proto | ||
| old_extensions1.proto | ||
| old_extensions2.proto | ||
| README.md | ||
| unittest.proto | ||
| unittest_custom_options_proto3.proto | ||
| unittest_import.proto | ||
| unittest_import_proto3.proto | ||
| unittest_import_public.proto | ||
| unittest_import_public_proto3.proto | ||
| unittest_issue6936_a.proto | ||
| unittest_issue6936_b.proto | ||
| unittest_issue6936_c.proto | ||
| unittest_issues.proto | ||
| unittest_proto3.proto | ||
| unittest_selfreferential_options.proto | ||
This directory contains unit test protos adapted from those in src/google/protobuf, and C#-specific test protos for regression tests against bugs found in the C# codegen or library.