[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [Tinycc-devel] Bugs found in TCC

From: Yann Bourrigault
Subject: RE: [Tinycc-devel] Bugs found in TCC
Date: Tue, 26 Jan 2010 14:30:39 +0000

Grischka wrote:

> Just on a note, there are two that might work correctly with current master 
> branch (http://repo.or.cz/w/tinycc.git)

Thanks for the advice. Actually, the bugs I found are not blocking for my 
purpose, meaning I've never faced one of them when compiling some source code 
generated by our product. For the moment I'll keep on working with the official 

> Also, I'm confused by this one ("unsigned + signed" should be unsigned, no?) 
> Maybe someone else can comment:

 > ->Problem with promotion on bit-fields. Some integral promotion are wrong  > 
 > with bit-fields.
 > int main()
 > {
 >     struct {
 >         unsigned int ufield  : 7;
 >         int  field  : 7;
 >         int  field2 : 7;
 >     } bit;
 >     int i1;
 >     short sh1;
 >     char ch1;
 >     bit.ufield = 10;
 >     i1 = -11;
 >     assert((bit.ufield + i1) < 0);
 >     sh1 = -11;
 >     assert((bit.ufield + sh1) < 0);
 >     bit.field = -11;
 >     assert((bit.ufield + bit.field) < 0);
 >     ch1 = -11;
 >     assert((bit.ufield + ch1) < 0);
 >     return 0;

 > }

Concerning this example, there is actually no clear statement in the C99 norm. 
My guess is that the size of the original type in which a bit-field is declared 
is only used to determine the alignment of the structure. In fact, some 
compilers allow to declare bit-fields with types smaller than int, which 
enables to have a different alignment for the structure. Considering promotion, 
the bit-field size should be taken as the actual type size, meaning that ufield 
must be considered as an uint7 instead of an uint32.
Thus, the rule "If an int can represent all values of the original type, the 
value is converted to an int." applies. Indeed, all the values stored in a 
uint7 may be stored in an int32, so the promotion is made on int.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]