On Fri, 2009-08-14 at 08:05 +0200, Christoph Spiel wrote:
> Hi Elnatan!
> 
> > CIL mistakenly casts the operands of && and || to intType, when in
> > fact they are only required to have scalar type. This can lead to a
> > bug if the operands have type larger than int and have values which
> > truncate to 0 when cast to an int (and if useLogicalOperators is set
> > to true).
> 
>         IIRC, the C Standard says both operands of the logical
> operators _separately_ undergo the "usual unary conversions".
> Sloppily phrased, this means all integers with a conversion
> rank (CR) less than 40 get promoted to those with CR 40,
> i.e. "int" or "unsigned int", and any with a higher CR are left
> untouched.

I think you mean the "usual arithmetic conversions" but, at least as I
read the Standard, these do *not* apply to operands of && and ||. (For
almost every other operator, the Standard seems to make it explicit when
conversions are applied to operands, and nothing is said for && and ||.)

> > I believe removing the cast solves the problem, but I'm not
> > sure whether enumerations should still be cast to intType.
> 
>         The Standard only requires that enumerations are
> represented as an implementation-defined integer type.  I know
> compilers that use "char", "short int", or "int" depending on the
> number of elements in a particular enum.  However, it is
> conceivable that a compiler wants to encode a huge enum (think of
> auto-generated parser jump tables) as "long int", i.e. at CR 50.
> In this case a cast-to-int could be fatal.
> 
> If we can rely on the ekind field of enuminfo, we could trivially
> cast the enum to its ekind and then perform the "usual unary
> conversions".  What do you think about that?

Even in this case, I don't they should be cast. Enumerations types *are*
scalar types, and that's all the operands of && and || are supposed to
be.

-Elnatan


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
CIL-users mailing list
CIL-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cil-users

Reply via email to