https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71567
Bug ID: 71567 Summary: Incorrect loop optimization Product: gcc Version: 4.8.5 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: tyoma.ariv at gmail dot com Target Milestone: --- #define NIN 2 struct struct1 { char ggint[NIN][6]; char dummy; }; /*----------------------------------------------------------------------*/ int get_struct1cnt(struct struct1 *gr) { int i=0 ; for ( i=0 ; *(gr->ggint[i]) != '\0' && i < NIN ; ++i ) ; return i ; } /*----------------------------------------------------------------------*/ int main (int argc, char **argv) { struct struct1 grp = {0}; for ( int i=0 ; i < NIN ; i++ ) grp.ggint[i][0] = 'A'+i; printf("%d\n", get_struct1cnt (&grp)); return 0; } When compiled with gcc -O -std=c99 one.c: the program display 1. When compiled with gcc -std=c99 one.c: the programm display 2 as expcted If optimization level is -Og or not, the program displays 2, if optimization level is -O or higher, the program displays 1. Note: removing dummy field from struct struct1 make this bug not reproducable