Mail Archives: djgpp-workers/1998/03/09/12:34:36
Hi!
I'm not sure whether it is a new bug. I've found it with the latest
test version of perl.
This program is a feature test for perl. Compile this with -O0 and it
prints 0, but with -O2 it prints 1. This bug also appears on linux
(2.7.2.3).
And another interesting thing: when you compile this with 2.8.0 and
-O2, gcc optimize out the whole test and the assembly is just an
exit(1)! Wow!
Laszlo
ps: the original code doesn't have any printf
---------8<-----------
#include <sys/types.h>
#include <signal.h>
void blech() { exit(7); }
void blech_in_list() { exit(4); }
unsigned long dummy_long(p) unsigned long p; { return p; }
unsigned int dummy_int(p) unsigned int p; { return p; }
unsigned short dummy_short(p) unsigned short p; { return p; }
main()
{
double f = -123.;
unsigned long along;
unsigned int aint;
unsigned short ashort;
int result = 0;
signal(SIGFPE, blech);
along = (unsigned long)f;
aint = (unsigned int)f;
ashort = (unsigned short)f;
if (along != (unsigned long)-123)
result |= 1;
if (aint != (unsigned int)-123)
result |= 1;
if (ashort != (unsigned short)-123)
result |= 1;
f = (double)0x40000000;
f = f + f;
along = 0;
along = (unsigned long)f;
if (along != 0x80000000)
result |= 2;
f -= 1.;
along = 0;
along = (unsigned long)f;
if (along != 0x7fffffff)
result |= 1;
f += 2.;
along = 0;
along = (unsigned long)f;
if (along != 0x80000001)
result |= 2;
if (result)
printf ("%d",result),exit(result);
signal(SIGFPE, blech_in_list);
f = 123.;
along = dummy_long((unsigned long)f);
aint = dummy_int((unsigned int)f);
ashort = dummy_short((unsigned short)f);
if (along != (unsigned long)123)
result |= 4;
if (aint != (unsigned int)123)
result |= 4;
if (ashort != (unsigned short)123)
result |= 4;
printf ("%d",result);
exit(result);
}
- Raw text -