patch: boolean bitfield init

Is it possible the code is using the wrong one?

Not really. There are a number of ways to look at the problem but it
is hard to separate them without clarifying the invariants on bit-field
initializers which at the least I don't understand (and may not exist?).

The immediate problem is that the constant being used to initialize
the bit-field is of type bool (this is a separate bug) even though the bit-
field has width > 1. This breaks the algorithm used to initialize the struct
because it expects to be able to extract all the required bits from the
constant. Since it is not clear that this is an invariant that is supposed to
exist my immediate goal was to just not have codegen assert on it.

Most likely the more correct fix is that the initializer on the RHS for field
'a' should have type char but this is more invasive. Hence the FIXME
comment. :slight_smile:

- Daniel

But the size of type bool should be 8 bits, otherwise the test case is invalid.
For example,
  struct { int a:199; } b;

The immediate problem is that the constant being used to initialize
the bit-field is of type bool (this is a separate bug) even though the bit-
field has width > 1. This breaks the algorithm used to initialize the struct
because it expects to be able to extract all the required bits from the
constant.

Yeah... that algorithm is actually my code. As far as I can tell, the
patch is correct, although it seems like overkill to extend the width
of V all the way to the width of the bitfield.

Most likely the more correct fix is that the initializer on the RHS for field
'a' should have type char but this is more invasive. Hence the FIXME
comment. :slight_smile:

Here's the situation with relation to the standards: in C99, the code
is illegal, because the bit-field width exceeds the width of the type.
We're missing an diagnostic in Sema for this. In C++, at least per
the current C++0x draft, the extra bits are treated as padding bits,
so Sema is correct as-is. The only question is, what the heck gcc is
doing here? As far as I can tell, it seems to be treating the _Bool
bitfield as a unsigned char bitfield. Anyone know more?

-Eli