[cfe-dev] different signedness for bitfield 'char' and plain 'char'

Eli Friedman eli.friedman at gmail.com
Tue Jul 30 11:09:30 PDT 2013


On Tue, Jul 30, 2013 at 10:51 AM, Robert Lytton <robert at xmos.com> wrote:
> Hi,
>
> I have altered isSignedCharDefault()  to make 'char' unsigned for the xcore
> target too.
> (The signedness of 'char' is an ABI issue as far a the standard is
> concerned.)
>
> My problem now is that char-bitfields are also being made unsigned.
> According to the standard the members of a bitfield are always signed unless
> explicitly marked unsigned.
>
> Hence I need:
>     'char' to be unsigned.
>     but the bit field 'char' to be signed.
>
> viz:
>     // ABI requires plain 'char' to be unsigned
>     char c = (char)-1;
>     assert(c >= 0);
>
>     // members of a bitfield are always signed unless explicitly marked
> unsigned
>     struct char_sign { char x : 1; };
>     char_sign.x = 1;
>     assert(char_sign.x < 0);
>
>
> Is this possible in clang?
> If not, could anyone like to point me in the right direction to where the
> fix would be necessary?

That's sort of strange... but probably not too hard.

CGBitFieldInfo::MakeInfo in CGRecordLayoutBuilder.cpp is the obvious
place.  I'm trying to think of anywhere else that would actually need
to be modified... I mean, it theoretically affects integer promotion,
but in practice sizeof(int) > sizeof(char) so that doesn't actually
matter.

-Eli



More information about the cfe-dev mailing list