================
@@ -15917,12 +15917,15 @@ 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) keep
+ // only the type's width as the value container. The extra declared bits
+ // are padding and follow that container (Itanium C++ ABI ยง2.4, II.1(b)).
+ // getIntWidth may be narrower still (bool, _BitInt); those occupied bits
+ // are the low-order bits of the value container.
+ const uint64_t ValueFieldBits =
+ std::min(DeclaredSizeInBits, Ctx.getTypeSize(Field->getType()));
const uint64_t OccupiedSizeInBits =
- std::min(DeclaredSizeInBits,
+ std::min(ValueFieldBits,
static_cast<uint64_t>(Ctx.getIntWidth(Field->getType())));
----------------
vhscampos wrote:
As it turns out, `_BitInt(5) a : 6` is not an over-sized bitfield!
`sizeof(_BitInt(5))` is 8, which is greater than 6. The memory representation
in big endian is `1111 1100`, but the actual value lives in bits 6-2. Bit 7 is
just a sign-extension bit.
You are right indeed. Thanks for catching my mistake. I wrongly thought it was
an over-sized bitfield.
https://github.com/llvm/llvm-project/pull/225494
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits