[Bug middle-end/50066] [4.7 Regression] Bad signed int to unsigned long long conversion
hjl.tools at gmail dot com
gcc-bugzilla@gcc.gnu.org
Wed Nov 30 21:19:00 GMT 2011
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50066
H.J. Lu <hjl.tools at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |REOPENED
Last reconfirmed| |2011-11-30
Resolution|INVALID |
Ever Confirmed|0 |1
--- Comment #17 from H.J. Lu <hjl.tools at gmail dot com> 2011-11-30 20:52:59 UTC ---
(In reply to comment #6)
> On Sat, 13 Aug 2011, hjl.tools at gmail dot com wrote:
>
> > --- Comment #4 from H.J. Lu <hjl.tools at gmail dot com> 2011-08-13 12:09:16 UTC ---
> > This code comes from mpz/set_si.c in gmp:
> >
> > void
> > mpz_set_si (mpz_ptr dest, signed long int val)
> > {
> > mp_size_t size;
> > mp_limb_t vl;
> >
> > vl = (mp_limb_t) (unsigned long int) (val >= 0 ? val : -val);
>
> So that GMP code is buggy. Change it to
>
> vl = (mp_limb_t) (val >= 0 ? (unsigned long int) val : -(unsigned long int)
> val);
>
> and it will be valid.
It doesn't work:
[hjl@gnu-6 tmp]$ cat x.c
#include <stdio.h>
#include <limits.h>
unsigned long long
__attribute__ ((noinline))
foo (signed int v_digit)
{
unsigned long long x;
x = (unsigned long long) (v_digit >= 0 ? (unsigned int) v_digit : (unsigned
int) -v_digit);
return x;
}
int
main ()
{
unsigned long long x;
x = foo (INT_MIN);
printf ("%lld\n", x);
x = foo (INT_MAX);
printf ("%lld\n", x);
return 0;
}
[hjl@gnu-6 tmp]$ /export/build/gnu/gcc-x32/release/usr/gcc-4.7.0-x32/bin/gcc
-O2 x.c
[hjl@gnu-6 tmp]$ ./a.out
-2147483648
2147483647
[hjl@gnu-6 tmp]$ /export/build/gnu/gcc-x32/release/usr/gcc-4.7.0-x32/bin/gcc -O
x.c
[hjl@gnu-6 tmp]$ ./a.out
2147483648
2147483647
[hjl@gnu-6 tmp]$
More information about the Gcc-bugs
mailing list