This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/23282] New: wrong results at -O on x86


Using gcc 4.0.1 :

Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: /data1/vondele/gcc-401/gcc/configure --
prefix=/data1/vondele/gcc-401/result --with-gmp-dir=/data1/vondele/gmp-4.1.4/ -
-with-mpfr=/home/vondele/ --enable-languages=c,f95
Thread model: posix
gcc version 4.0.1

The following program generates wrong results (-1 instead of 4 for the second 
number printed out) if compiled with -O. It works fine with gcc 3.3.4 and the 
portland group c compiler:

#include <stdio.h>

void sub(int *m) {
  int index, l, count;

  l = 2;

  for(count=2; count>0; count--, l++) {
    index = l*l+1;

    printf("%d\n", m[index-2*l]);

    m[index+1] = -1;
  }
}


int main(void) {
  int i, m[20];

  for(i=0; i<20; i++)
    m[i] = i;

  sub(m);

  for(i=0; i<20; i++)
    printf("%d ", m[i]);

  putchar('\n');
}

vondele> gcc test.c
vondele> ./a.out
1
4
0 1 2 3 4 5 -1 7 8 9 10 -1 12 13 14 15 16 17 18 19

vondele> gcc -O test.c
vondele> ./a.out
1
-1
0 1 2 3 4 5 -1 7 8 9 10 -1 12 13 14 15 16 17 18 19

-- 
           Summary: wrong results at -O on x86
           Product: gcc
           Version: 4.0.1
            Status: UNCONFIRMED
          Severity: critical
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jv244 at cam dot ac dot uk
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23282


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]