Hi,
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 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.
regards Jan Kardell MIDA Systemutveckling AB
On 14 Mar 2003 at 9:03, 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....
With this compiler (i486-pc-mingw32):
gpc version 20021128, based on gcc-3.2.1 (MinGW special 20021202-2)
I get:
$99: agc= 3.999 (this value should be 3.999) $00: agc= 9.998 (this value should be 9.998) $FF: agc= 0.000 (this value should be 0.000)
...with either -O0, -O1, or -O2. This is from a newer GPC, a different platform, and probably a newer version of GCC. Still, for this combination, your program works.
-- Dave
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
Frank Heckenbach wrote:
... snip ...
AFAIK, binaries for DJGPP, Mingw and Mac OS X are regularly updated by Maurice Lombardi, The Chief and Adriaan van Os, respectively.
AFAICT the following is the latest Maurice has done for DJGPP:
[1] c:>gpc --version gpc.exe 20021128, based on gcc-3.2.1
which inhibits me upgrading gcc to 3.2.2, and from upgrading gpc. If he has done any later ones I have seen no announcements here.