Need clarification for zero width bitfield

40 views
Skip to first unread message

H.J. Lu

unread,
Nov 29, 2021, 7:24:51 AM11/29/21
to x86-64-abi
From Jakub Jelinek ja...@redhat.com:

The current psABI doesn't seem to mention zero sized bitfields at all
explicitly, so perhaps theoretically they should be treated as INTEGER class,
but if they are at positions multiple of 64 bits, then it is unclear into
which eightbyte they should be considered, whether the previous one if any
or the next one if any. I guess similar problem is for zero sized
structures, but those should according to algorithm have NO_CLASS and so it
doesn't really make a difference. And, no compiler I'm aware of treats
the zero sized bitfields at 64 bit boundaries as INTEGER class, LLVM/ICC are
ignoring such bitfields everywhere, GCC ignores them at those boundaries
(and used to ignore them in C++ everywhere). I guess my preferred solution
would be to say explicitly that zero sized bitfields are NO_CLASS.

--
H.J.

Michael Matz

unread,
Nov 29, 2021, 9:22:15 AM11/29/21
to x86-64-abi
Hello,
For context, this was the mail from Jakub (containing some text explaining
a potential patch):

https://gcc.gnu.org/pipermail/gcc-patches/2021-November/585630.html

and this is the bug report about a problem in GCC regarding zero-width
bit-fields, where there was a difference between C and C++ (now fixed):

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

and Jakub now contemplates to add a -Wpsabi warning about this case but
wants to have the various psABIs be clarified.

My take: I see no reason why the particular bit position of a zero-width
bit-field should matter: if it's naturally aligned already then it doesn't
matter, and if it isn't then the following fields should be aligned as
requested. So that's a case for handling zero-width bit-fields
consistently.

Now, NO_CLASS or INTEGER: conceptually NO_CLASS is the right choice, there
are no bits in a zero-width bit-field, nothing is in there that could have
a class. And it's certainly unexpected that a zero-width bit-field
tacked between two floats makes the whole thing not be class SSE/X87,
especially because it does so only when the bitposition isn't 64-bit
aligned.

So, yeah, I think zero-width bit-fields should be explicitely NO_CLASS for
class merging purposes (instead of INTEGER). The other effects of them
regarding alignment and spacing of following fields not withstanding of
course, that's orthogonal.

Any other opinions?


Ciao,
Michael.

H.J. Lu

unread,
Dec 20, 2021, 4:31:34 PM12/20/21
to Michael Matz, x86-64-abi
Here is the patch. The merge request is at

https://gitlab.com/x86-psABIs/x86-64-ABI/-/merge_requests/30

--
H.J.
0001-Treat-zero-width-bit-fields-as-NO_CLASS.patch

Michael Matz

unread,
Jan 10, 2022, 9:25:11 AM1/10/22
to H.J. Lu, x86-64-abi
Hello,
As there were no other opinions forthcoming, I've merged that now.
Thanks!


Ciao,
Michael.
Reply all
Reply to author
Forward
0 new messages