PR c/6677 and al.
Eric Botcazou
ebotcazou@libertysurf.fr
Wed May 29 03:19:00 GMT 2002
> > j = ((char) (i << 1)) / 2;
> [...]
> > The proposed fix is to disallow the second transformation when the type
> > is signed and the global operation not a MULT_EXPR.
>
> This isn't the best thing, since we _are_ allowed to produce the screwey
> result with "int" instead of char.
Do you mean that [int being 32-bit]
int i = 0x7fffffff;
int j;
j = (i << 1) / 2;
is allowed to return j = 0x7fffffff ?
Note that gcc 2.91.66, gcc 2.95.3 and Borland C++ 5.5.1 return -1, while gcc
2.96 and gcc 3.1 return 0x7fffffff.
> And indeed, it would appear that your other problem
>
> > j = ((char) (i * 2)) / 2;
>
> is the same root problem. We can't look through the narrowing cast as
> readily as we're doing.
The problem is that we don't look through the narrowing cast in the fist
case: (i<<1):QI is really transformed into (i:QI) << (1:QI), which is valid
per se.
--
Eric Botcazou
ebotcazou@multimania.com
More information about the Gcc-patches
mailing list