Handle bit-fields in unions for __builtin_clear_padding
GCC's `__builtin_clear_padding` now correctly handles bit-fields within unions, preventing incorrect clearing of bits.
This commit fixes a bug in GCC’s __builtin_clear_padding where bit-fields within unions were not properly accounted for. The implementation now correctly calculates and applies bitmasks to clear only padding bits, irrespective of the union’s active member, ensuring that non-padding bits within bit-fields are preserved.
In Details
The gimple-fold pass in GCC's middle-end optimizes GIMPLE code. This patch addresses __builtin_clear_padding's handling of unions containing bit-fields. Previously, the logic in clear_padding_union did not correctly account for bit-field members, potentially clearing bits outside their defined range. The fix introduces a new clear_padding_bitfield function, largely migrating logic from clear_padding_type, and uses it within clear_padding_union to ensure accurate padding clearing for bit-fields within unions.
- GIMPLE
- GCC's internal three-address code representation, used as an intermediate language between the front-end and back-end optimization passes.
- gimple-fold
- A GCC optimization pass that performs constant folding and other algebraic simplifications on GIMPLE code.
- __builtin_clear_padding
- A GCC built-in function (introduced in GCC 11) that clears padding bits within a data structure, setting them to zero. This can be useful for ensuring consistent memory layouts or preparing data for serialization.
- union
- A composite data type that allows storing different data types in the same memory location. Only one member of a union can be active at any given time.
- bit-field
- A data member within a struct or union that is allowed to occupy only a specified number of bits, which may be less than the number of bits in its data type.