[cfe-dev] A patch for integer promotions.
Enea Zaffanella
zaffanella at cs.unipr.it
Wed Aug 19 04:21:00 PDT 2009
Eli Friedman wrote:
> On Mon, Aug 17, 2009 at 11:32 PM, Enea Zaffanella<zaffanella at cs.unipr.it> wrote:
>> Here is attached the cumulative patch.
>> Is it possible they get applied before code is frozen?
>
> Patch looks great; applied in r79412. Sorry about the delay!
>
> -Eli
>
>
Hi.
Thank you for applying the patch. We seem to have identified another
promotion problem, this time related to the promotion of bit-fields.
Apparently, clang accepts further integral bit-field types besides those
that are mandated by the C99 standard (_Bool, signed int, unsigned int).
However, the code meant to check for bit-field promotions will only
insert the promotions for the types mandated by the standard, so that,
e.g., a bit-field having `unsigned short' type will not be subject to
bit-field promotion rules; it will instead be subject to usual promotion
rules.
Example: suppose the following code is parsed on a target where short
and int have the same size (e.g., pic16).
struct S {
unsigned short us : 12;
} s;
int foo(void) {
return s.us + s.us;
}
Here clang inserts the usual (i.e., non-bit-field) promotion, obtaining
code equivalent to
int foo(void) {
return ((int) (((unsigned int) (s.us)) + ((unsigned int) (s.us))));
}
In contrast, if the bit-field promotions would be applied, we would
obtain code equivalent to:
int foo(void) {
return (int) (s.us) + (int) (s.us);
}
Now, even though we are talking about an implementation-defined
behavior, I guess that clang is striving for maximum compatibility with
GCC and, according to our observation, GCC applies bit-field promotions
to *all* bit-fields having a declared bit-size smaller than that of an
int, no matter what their declared type is.
This behavior sounds reasonable, so please find here attached the
corresponding patch.
Besides implementing gcc bit-field extensions behavior, the patch also
moves the corresponding function into ASTContext, so as to make it
easily available to clients:
QualType ASTContext::isPromotableBitField(Expr *E);
Let us know if there is anything unclear.
Cheers,
Enea Zaffanella.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: BitField_Promotion.patch
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20090819/dd76abe6/attachment.ksh>
More information about the cfe-dev
mailing list