optimization/2512: optimization > -O gives incorrect loop processing (gcc, g++)

linux62i@yahoo.com linux62i@yahoo.com
Mon Apr 9 01:26:00 GMT 2001


>Number:         2512
>Category:       optimization
>Synopsis:       optimization > -O gives incorrect loop processing (gcc, g++)
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Apr 09 01:26:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Vladislav Belogroudov
>Release:        2.95.2
>Organization:
>Environment:
linux ~2.2.17
gcc 2.95.2 , 2.95.3 1991024-20000220
mandrake,debian... INTEL problem only (p133 processor in my case).
I tried DEC,SUN - works perfectly.
>Description:
when trying to optimize a program
with optimization level more than 1
gcc (g++) skips one iteration in 'for' loop

There is simple task. Two arrays 
int a[] = {0,1,2,3,4,5}; 
int b[] = {0,0,0,0,0,0}; // array to fill in
int i = 0; // counter

I am trying to put 1,2,3,4,5 from a[] into b[],
without zero, and into rest cell put 99.

g++ probe.cc
./a.out
5
1 2 3 4 5 99

g++ -02 probe.cc
./a.out
5
1 2 3 4 0 99

source file is attached





 
>How-To-Repeat:
see description
>Fix:
n/a
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="probe.cpp"
Content-Disposition: inline; filename="probe.cpp"

#include <iostream>

int main()
{

  int a[] = { 0, 1, 2, 3, 4, 5};
  int b[] = { 0, 0, 0, 0, 0, 0};
  int i = 0;

  for (i = 0; i < 5; i++) {
    b[i] = a[i+1];
  }  
  
  cerr << i << endl;

  b[i] = 99;

  for (i = 0; i < 6; i++) {
    cerr << b[i] << " ";
  }  
  
  cerr << endl;


  return 0;
}



More information about the Gcc-bugs mailing list