Jan Kardell wrote:
I've run into a code generation bug with GPC 2.1. When I use optimization -O2, a calculation uses an uninitialized register. With -O1 the generated code looks very different, and it works.
Compiler: Binary distribution of gpc 2.1 downloaded from http://www.gnu-pascal.de/binary/gpc-2.1-with-gcc.i686-pc-linux-gnu.tar.gz Computer: i586 running SuSE 7.2, kernel stock 2.4.17
I can reproduce it with the latest snapshot. It happens with gcc-2.95, not with gcc-2.8.1 or gcc-3.x. Here's a simplified programs that still exhibits the bug:
program foo;
var a: Integer; t: Byte = 10;
procedure r (a: Integer); begin end;
procedure q; begin end;
procedure p; var i: Integer; begin i := t; i := 2 - t; q; r (2 - t); a := i end;
begin p; WriteLn (a) end.
Translated literally to C, it shows the same bug with gcc-2.95 and -O2:
extern void printf (const char *, ...);
int a;
char t = 10;
static void r (int a) { }
static void q () { }
static void p () { int i; i = t; i = 2 - t; q (); r (2 - t); a = i; }
int main () { p (); printf ("%i\n", a); }
# gcc-2.8.1 -O x.c && ./a.out -8 # gcc-2.8.1 -O2 x.c && ./a.out -8 # gcc-2.95 -O x.c && ./a.out -8 # gcc-2.95 -O2 x.c && ./a.out 1 # gcc-3.2 -O x.c && ./a.out x.c:1: warning: conflicting types for built-in function `printf' -8 # gcc-3.2 -O2 x.c && ./a.out x.c:1: warning: conflicting types for built-in function `printf' -8
So it's apparently a backend bug. If you want to report it to the GCC people, you can use this test program, of course, but AFAIK, they don't care about bugs in older gcc versions. To avoid it, you might have to use another backend version or not use `-O2' ...
I have not tried any newer versions of the compiler since i could not find binary versions and I do hesitate a bit to compile one myself. If binary versions of compiler snapshots where available, my guess is you would get a bigger testing audience.
I've now uploaded a Linux binary of the 20030323 snapshot (though still with gcc-2.95) ...
AFAIK, binaries for DJGPP, Mingw and Mac OS X are regularly updated by Maurice Lombardi, The Chief and Adriaan van Os, respectively.
Frank