Package: gcc-snapshot Version: 20041030-1 Severity: normal Hello Matthias,
gcc-snapshot generate incorrect code for the attached file with -O1 and above. It is correctly compiled with -O0. %gcc div.c -O0 %./a.out 1 2 4 8 5 10 20 40 25 50 100 200 125 250 500 1000 %gcc div.c -O1 %./a.out 1 2 5 10 1073835008 -1021043573 1073789904 -1073742211 134518760 1575782908 0 0 1073789904 0 1814429448 0 gcc 3.3 and 3.4 compile it correctly at -O3. Cheers, Bill. -- System Information: Debian Release: 3.1 APT prefers unstable APT policy: (500, 'unstable') Architecture: i386 (i686) Kernel: Linux 2.4.26-acpi Locale: LANG=français, LC_CTYPE=français (charmap=ISO-8859-1) Versions of packages gcc-snapshot depends on: ii binutils 2.15-4 The GNU assembler, linker and bina ii libart-2.0-2 2.3.16-6 Library of functions for 2D graphi ii libatk1.0-0 1.6.1-5 The ATK accessibility toolkit ii libc6 2.3.2.ds1-18 GNU C Library: Shared libraries an ii libglib2.0-0 2.4.7-1 The GLib library of C routines ii libgtk2.0-0 2.4.13-1 The GTK+ graphical user interface ii libpango1.0-0 1.4.1-4 Layout and rendering of internatio ii zlib1g 1:1.2.2-3 compression library - runtime -- no debconf information
#include <stdlib.h> #include <stdio.h> typedef long *GEN; GEN stoi(long n) { GEN z=(GEN)calloc(3,sizeof(GEN)); z[2]=n; return z; } GEN mulii(GEN x, GEN y) { return stoi(x[2]*y[2]); } void divisors_bug(long l, GEN *t, GEN e, GEN P) { long i, j; GEN *d, *t1, *t2, *t3; d = t; *++d = stoi(1); for (i=1; i<l; i++) for (t1=t,j=e[i]; j; j--) { for (t2=d, t3=t1; t3<t2; ) *++d = mulii(*++t3, (GEN)P[i]); t1=t2; } } int main(void) { long e[3]={0,3,3}; long P[3]={0,(long)stoi(2),(long)stoi(5)}; GEN t[17]; long i; divisors_bug(3,t,e,P); for(i=1;i<17;i++) printf("%ld ",t[i][2]); printf("\n"); return 0; }