egcs-1.0.2 optimization bug

Craig Wiegert wiegert@quintessence.uchicago.edu
Thu Apr 23 23:17:00 GMT 1998


The following code runs properly without optimization, but produces
incorrect results when optimized:

----------------

#include <stdio.h>
#include <math.h>

double foo(double z1, double z2)
{
    z1 += 1.0;
    z2 += 1.0;
    return pow(z1, 1.5) / pow(z2, 1.0);
}

int main()
{
    double tmp;

    tmp = foo(0.0, 3.0);
    printf("result is %g, should be %g\n", tmp, 0.25);
    return 0;
}

---------------

> gcc -g test.c -lm
> ./a.out 
result is 0.25, should be 0.25

> gcc -g -O1 test.c -lm
> ./a.out
result is Inf, should be 0.25

> gcc -v
Reading specs from /usr/lib/gcc-lib/i386-linux/egcs-2.90.27/specs
gcc version egcs-2.90.27 980315 (egcs-1.0.2 release)

> uname -a
Linux quintessence.uchicago.edu 2.0.33 #2 Fri Jan 16 15:40:18 CST 1998
i686 unknown


The RPMS used in installing the compiler and related utils:
glibc-2.0.7-7
glibc-devel-2.0.7-7
binutils-2.9.0.3-2
egcs-1.0.2-1

Please let me know if more info is needed.

  - Craig
    c-wiegert@uchicago.edu



More information about the Gcc-bugs mailing list