bug report

Anne-Marie GASTINEAU amgastineau@voonoo.net
Sun Nov 26 08:01:00 GMT 2000


I found an optimization bug on my linux box with the gcc compiler (gcc
coming with Mandrake 7.1).

There is a problem with the conversion : intmax_t -> double -> intmax_t.
The correct result is given with the option -O0.
If I remove the keyword volatile from l1, the problem is the same.

The attached file  are :
toto.O0.i and toto.O0.s are the intermediate file from -O0 compilation.
toto.O2.i and toto.O2.s are the intermediate file from -O0 compilation.


[bdl@localhost user]$ gcc --version
2.95.3

[bdl@localhost user]$ uname -a
Linux localhost.localdomain 2.2.15-4mdk #4 mer sep 20 21:02:27 CEST 2000
i586 unknown

[bdl@localhost user]$ gcc -O0 toto.c -o toto
[bdl@localhost user]$ ./toto
v=2305843009213693952
v=2305843009213693953
l>l1
v=2305843009213693951
l<l1
[bdl@localhost user]$ gcc -O2 toto.c -o toto
[bdl@localhost user]$ ./toto
v=2305843009213693952
v=2305843009213693953
v=2305843009213693951

My prgram is :
#include <stdio.h>
#include <inttypes.h>

void  LONGLONG22DBL(intmax_t l)
{
 double d1, d2;
 volatile intmax_t l1;
 d1 = l;
 d2 = d1;
 l1 = d1;
 if ( l<l1 )
 {
   printf("l<l1\n");
 }
 else if ( l>l1 )
 {
  printf("l>l1\n");
 }
}


int main()
{
 intmax_t v=1;
 v <<=61;
 printf("v=%"PRIiMAX"\n",v);
 LONGLONG22DBL(v);
 v+=1;
 printf("v=%"PRIiMAX"\n",v);
 LONGLONG22DBL(v);
 v-=2;
 printf("v=%"PRIiMAX"\n",v);
 LONGLONG22DBL(v);
 return 0;
}








-------------- next part --------------
A non-text attachment was scrubbed...
Name: toto.O0.i
Type: text/x-c
Size: 18683 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-bugs/attachments/20001126/1ede161e/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: toto.O0.s
Type: text/x-asm
Size: 2525 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-bugs/attachments/20001126/1ede161e/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: toto.O2.i
Type: text/x-c
Size: 22429 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-bugs/attachments/20001126/1ede161e/attachment-0002.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: toto.O2.s
Type: text/x-asm
Size: 2068 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-bugs/attachments/20001126/1ede161e/attachment-0003.bin>


More information about the Gcc-bugs mailing list