https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64255
Bug ID: 64255
Summary: failures with -O2 optimization on i >= 0 ? (unsigned
long) i : - (unsigned long) i
Product: gcc
Version: 5.0
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: vincent-gcc at vinc17 dot net
I get failures when building and testing MPFR with:
gcc (Debian 20141209-1) 5.0.0 20141209 (experimental) [trunk revision 218514]
on x86_64, using:
./configure --enable-assert=full CC=gcc-snapshot 'CFLAGS=-Wall -O2 -g'
Using -O1 only makes the problems disappear.
If I simplify the MPFR code to:
int
mpfr_set_si_2exp (mpfr_ptr x, long i, mpfr_exp_t e, mpfr_rnd_t rnd_mode)
{
if (i == 0)
{
return 0;
}
else
{
unsigned long ai;
ai = i >= 0 ? (unsigned long) i : - (unsigned long) i;
if ((i >= 0 ? (unsigned long) i : - (unsigned long) i) != ai)
printf ("Error!\n");
printf ("i = %ld\n", i);
printf ("ai = %lX\n", ai);
return 0;
}
}
in set_si_2exp.c, and call:
mpfr_set_si_2exp (x, 1, 0, 0);
I get:
i = 1
ai = FFFFFFFFFFFFFFFF
If I remove the
if ((i >= 0 ? (unsigned long) i : - (unsigned long) i) != ai)
printf ("Error!\n");
test, I get:
i = 1
ai = 1
as expected.
I don't know why, but I didn't manage to get a standalone testcase.