[Bug target/102024] [12 Regression] zero width bitfields and ABIs

wschmidt at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Aug 25 19:33:52 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102024

--- Comment #11 from Bill Schmidt <wschmidt at gcc dot gnu.org> ---
Actually, on further review, I guess we have additional concerns.  Unnamed
bitfields also have the effect of updating alignment of the subsequent field of
a structure.

"The types of unnamed bit fields have no effect on the alignment of a structure
or union.  However, the offsets of an individual bit field's member must comply
with the alignment rules. An unnamed bit field of zero width causes sufficient
padding (possibly none) to be inserted for the next member, or the end of the
structure if there are no more nonzero width members, to have an offset from
the start of the structure that is a multiple of the size of the declared type
of the zero-width member."

That's from ELFv2, but I imagine the same language exists in ELFv1, as I don't
believe this was meant to be a change from the previous ABI.

An example from the ABI to test is:

struct {
  char c;
  int : 0;
  char d;
  short : 9;
  char e;
};

I wouuld expect that prior to Jakub's change, we would not see three bytes of
pad between c and d, but with his change, we would.

We can probably warn for this as well, but might be a little trickier.  This is
more likely to come up than the homogeneous aggregate case, I guess.


More information about the Gcc-bugs mailing list