This is the mail archive of the
mailing list for the GCC project.
Re: Fix PR57886, invalid folding of conversion
- From: Marc Glisse <marc dot glisse at inria dot fr>
- To: Michael Matz <matz at suse dot de>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Fri, 12 Jul 2013 16:09:53 +0200 (CEST)
- Subject: Re: Fix PR57886, invalid folding of conversion
- References: <alpine dot LNX dot 2 dot 00 dot 1307121515540 dot 4274 at wotan dot suse dot de>
- Reply-to: gcc-patches at gcc dot gnu dot org
On Fri, 12 Jul 2013, Michael Matz wrote:
GCC happily transforms (float)-z into -(float)z, even when z is of
unsigned type (when it's larger than float). That's wrong (the result
should always be positive, because -z is). It seems to me that this bug
exists in all reasonably recent GCC versions. The checking in
convert_to_real is wrong, it compares type precisions of different
classed types. The change with the least impact is to reject only
TYPE_UNSIGNED inner types, but perhaps it would be better to only do the
transformation if the inner type is FLOAT_TYPE_P as well.
If you want to handle integers, shouldn't you test TYPE_OVERFLOW_UNDEFINED
(for LONG_MIN)? FLOAT_TYPE_P does seem safer indeed.
I'd replace TREE_TYPE (expr) with itype on the next line, it is confusing
to refer to it under 2 different names on 2 consecutive lines.