gcc version 3.3, Apple build 1495, ppc-darwin. command-line: gcc -O3 file.c output: 1 2 0 0 5 6 0 0 9 10 0 0 13 14 0 0 17 18
command-line: gcc -O0 file.c output: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 Compile and run the following file with optimization < O2. The output is a list of integers from 1--18. When compiled with >= O2, the list contains "holes" (the integers 3,4,7,8,11,12,15,16 display as 0). #include <stdlib.h> #include <stdio.h> static void f(int in1, int *out11); static void init(int in1, int *out1, int *out2, int *out11, int *out21); static void dump(int *out11); int main() { int out11[18] = { 0 }; int in1 = 0; f(in1,out11); return 0; } static void f(int in1, int *out11) { int b_out21 = 0; int b_out11[18] = { 0 }; int b_out5 = 0; int b_out2 = 0; int b_out1 = 0; init(in1, &b_out1, &b_out2, (int *)b_out11, &b_out21); for(b_out2 = 0; b_out2 < 9; b_out2++) { for(b_out5 = 0; b_out5 < 2; b_out5++) { out11[b_out5 + (b_out2 << 1)] = b_out11[b_out5 + (b_out2 << 1)]; } } dump(out11); } static void init(int in1, int *out1, int *out2, int *out11, int *out21) { int i; for(i = 0; i < 18; ++i) { out11[i] = i+1; } } static void dump(int *out11) { int i; for(i = 0; i < 18; ++i) { printf("%d ", out11[i]); } printf("\n"); } -- Summary: Simple nested for loop generates bad code on mac in O2, O3 Product: gcc Version: 3.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: john dot elliott at mathworks dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27008