[cfe-dev] patch: boolean bitfield init

Daniel Dunbar daniel at zuster.org
Thu Jul 17 11:14:26 PDT 2008


> 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. :)

 - Daniel


----- Original Message ----
From: Chris Lattner <clattner at apple.com>
To: Daniel Dunbar <daniel at zuster.org>
Cc: cfe-dev at cs.uiuc.edu
Sent: Thursday, July 17, 2008 10:55:04 AM
Subject: Re: [cfe-dev] patch: boolean bitfield init


On Jul 17, 2008, at 10:50 AM, Daniel Dunbar wrote:

> This is a quick fix for initialization of _Bool bit-fields which
> have width > 1 (<rdar://problem/6078606>), as in:
> --
> struct {
>  _Bool a : 8;
>  int b : 9;
> } x = { 1, 0 };
> --
>
> This allows test-suite/SingleSource/UnitTests/2006-01-23- 
> InitializedBitField.c to build.

Hey Daniel,

Just to clarify, what is the problem here?  There are two different  
"get type size" predicates on ASTContext, one that returns _Bool as  
having size of 1 bit, and one that returns size of 8 bits (on  
x86-32).  Is it possible the code is using the wrong one?

-Chris




More information about the cfe-dev mailing list