Bug in gcc 2.95.2 optimizer for SPARC
Per Espen Hagen
Wed Jun 28 02:02:00 GMT 2000
While developing a program for controlling autonomous underwater
vehicles, we have discovered a bug in GCC 2.95.2. Specifically, the
optimizer (-O2) for SPARC generates incorrect code.
Sun Ultra 1 (also found on Ultra 2 and SS-10) running Solaris 7 MU 4.
% uname -a
SunOS hugin2 5.7 Generic_106541-08 sun4u sparc SUNW,Ultra-1
GCC 2.95.2, as downloaded from http://www.sunfreeware.com/
% gcc -v
Reading specs from
gcc version 2.95.2 19991024 (release)
We have managed to reproduce the bug in a simple program. Attached
please find a tar archive with the following files:
bug.c - The program (378 bytes)
bug - Executable (command line: "gcc -g -O2 -o bug bug.c")
output - Compilation command line and program output
Some of the code (such as the "case 2" in the switch) may seem like
noise, but it is necessary to trigger the bug. The bug manifests itself
between line 19 and 28. A member of a union (v.i) is divided by 1000
within the switch, but the new value is not preserved after the switch.
In effect, the union member is treated as a local variable in the
The bug does not appear under the other platforms we use (Solaris x86,
Linux x86), nor does it appear when compiling with -O1 or without
If you need any additional information, please mail me.
Per Espen Hagen, Principal Scientist
Norwegian Defence Research Establishment
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 13312 bytes
Desc: not available
More information about the Gcc-bugs