This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PR c/6677 and al.
"Eric Botcazou" <ebotcazou@libertysurf.fr> writes:
|> > > 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 ?
The value of (i << 1) is undefined according to the C standard
(6.5.7[#4]), thus setting j to 42 would be perfectly valid. :-)
Andreas.
--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux AG, Deutschherrnstr. 15-19, D-90429 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."