================
@@ -15917,13 +15917,17 @@ struct PaddingCalculator {
const uint64_t DeclaredSizeInBits = Field->getBitWidthValue();
- // Handle over-sized bitfields:
- // unsigned char a : 12;
- // In this case, DeclaredSizeInBits is 12, but the actually occupied bit
- // size is 8, while the remaining 4 bits are padding.
+ // Oversized bit-fields (declared width larger than the field type) occupy
+ // only the type's width. The extra declared bits are padding and follow
+ // the occupied bits (Itanium C++ ABI ยง2.4, II.1(b)).
+ // A bool bit-field occupies its whole declared width up to the size of
+ // bool, like GCC. _BitInt(N) occupies only its N value bits.
+ const QualType FieldTy = Field->getType();
const uint64_t OccupiedSizeInBits =
----------------
vhscampos wrote:
This is a bit confusing still because in the BitInt + BE case,
`OccupiedSizeInBits` is computed but never used.
For consistency and to avoid confusion, I think we should call
`OccupiedSizeInBits` the number of "protected" bits across all cases.
For simplicity, we should also make LE and BE consistent with each other, and
Clang consistent with gcc wherever applicable. We know that gcc doesn't support
`BitInt(N) : s` where `s > N` so we have more leeway in this case.
Proposal:
- For `bool`, the occupied size is `min(declared size, type_size)`. This seems
to be the current way, so good.
- For `_BitInt`, the occupied size is `min(declared size, type size)` as well.
The reasoning for the second point is somewhat based on
https://github.com/ARM-software/abi-aa/blob/main/aapcs32/aapcs32.rst#811arithmetic-types.
If you look at the BitInt case (scroll down), it does mention that the
non-significant bits are sign or zero-extended. Therefore I believe it is wiser
to "protect" the value bits and the extension bits.
https://github.com/llvm/llvm-project/pull/225494
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits