egcs-2.91.54: Bus error on sparc-sun-solaris2.51.

Fred Richardson frichard@bbn.com
Tue Sep 1 13:40:00 GMT 1998


Looks like an optimization bug:

  bash-2.00$ gcc -v
  Reading specs from /d4mutl/bybrad.dev/lib/gcc-lib/sparc-sun-solaris2.5.1/egcs-2.91.54/specs
  gcc version egcs-2.91.54 19980817 (gcc2 ss-980609 experimental)
  bash-2.00$ gcc -mcpu=ultrasparc -ggdb -funsigned-char -fno-exceptions main.c -o main 
  bash-2.00$ main
  Dividing one by two
    1/2=0.5
  bash-2.00$ gcc -mcpu=ultrasparc -ggdb -funsigned-char -fno-exceptions -O3 -funroll-loops -finline-functions -fomit-frame-pointer main.c -o main 
  bash-2.00$ main
  Dividing one by two
  Bus Error
  bash-2.00$ gdb main
  GNU gdb 4.17
  Copyright 1998 Free Software Foundation, Inc.
  GDB is free software, covered by the GNU General Public License, and you are
  welcome to change it and/or distribute copies of it under certain conditions.
  Type "show copying" to see the conditions.
  There is absolutely no warranty for GDB.  Type "show warranty" for details.
  This GDB was configured as "sparc-sun-solaris2.5.1"...
  (gdb) r
  Starting program: /net/orchid/u15/frichard/BybRad.2/src/lib/byblos/run_init/main 
  Dividing one by two

  Program received signal SIGBUS, Bus error.
  0x10a08 in main (argc=1, argv=0xeffff0e4) at main.c:8
  8	    fprintf(fp, "  %g/%g=%g\n", num, den, ret);
  (gdb) p ret
  No symbol "ret" in current context.
  (gdb) q
  The program is running.  Exit anyway? (y or n) y
  bash-2.00$ 



main.c:
#include <stdlib.h>
#include <stdio.h>
#include <math.h>

void print_result(FILE* fp, double num, double den)
{
    double ret = num/den;
    fprintf(fp, "  %g/%g=%g\n", num, den, ret);
    fflush(fp);
}

void test_floating_point_exceptions(void)
{
    double den;
    double num;
    double one = 1.0;
    double two = 2.0;

    printf("Dividing one by two\n"); 
    fflush(stdout);
    memcpy(&num, &one, sizeof(double));
    memcpy(&den, &two, sizeof(double));
    print_result(stdout, num, den);
}

int main(int argc, char* argv[])
{
    test_floating_point_exceptions();

    exit(0);
}



More information about the Gcc-bugs mailing list