mirror of
https://github.com/cc65/cc65.git
synced 2025-01-26 17:36:57 +00:00
Pad bit-fields only to the next byte
Fixes #1054. Previously, bit-fields followed by another field were aligned to two bytes. Bit-fields ending the struct were (and continue to be) aligned only to a single byte. ``` struct s { unsigned int x : 4; }; struct t { unsigned int x : 4; unsigned int y; }; ``` Before: `sizeof(struct s) == 1`, sizeof(struct t) == 4` After: `sizeof(struct s) == 1` sizeof(struct t) == 3`
This commit is contained in:
parent
9e881a497e
commit
9858e47dfd
@ -772,17 +772,19 @@ static SymEntry* ParseStructDecl (const char* Name)
|
||||
*/
|
||||
if (BitOffs > 0) {
|
||||
if (FieldWidth <= 0 || (BitOffs + FieldWidth) > INT_BITS) {
|
||||
/* Bits needed to byte-align the next field. */
|
||||
unsigned PaddingBitWidth = -BitOffs % CHAR_BITS;
|
||||
|
||||
/* We need an anonymous name */
|
||||
AnonName (Ident, "bit-field");
|
||||
|
||||
/* Add an anonymous bit-field that aligns to the next
|
||||
** storage unit.
|
||||
** byte.
|
||||
*/
|
||||
AddBitField (Ident, StructSize, BitOffs, INT_BITS - BitOffs);
|
||||
AddBitField (Ident, StructSize, BitOffs, PaddingBitWidth);
|
||||
|
||||
/* No bits left */
|
||||
StructSize += SIZEOF_INT;
|
||||
StructSize += (BitOffs + PaddingBitWidth) / CHAR_BITS;
|
||||
BitOffs = 0;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user