http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56661
Bug #: 56661 Summary: [4.8 regression] Incorrect code with -O1 -ftree-pre Classification: Unclassified Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization AssignedTo: unassig...@gcc.gnu.org ReportedBy: manisan...@gmail.com Using gcc version 4.8.0 20130316 (Red Hat 4.8.0-0.17) ----------------- main.c ----------------- typedef long unsigned int size_t; extern int printf (const char *__restrict __format, ...); extern void *malloc (size_t __size) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__malloc__)); void setb(int* b); void foo(int x){ if(x == 0){ int* b = malloc(3*sizeof(int)); while(b[0]); }else if(x == 1){ int i, j; int* b = malloc(3*sizeof(int)); for(i = 0; i < 2; i++){ setb(b); for(j = 0; j < 3; ++j){ printf("%d ", b[j]); } printf("\nb[0] = %d\n", b[0]); } } } extern int g_x; int main(){ foo(g_x); return 0; } ----------------- stuff.c ----------------- void setb(int* b){ b[0] = b[1] = b[2] = 1; } int g_x = 1; ------------------------------------------- $ gcc -O1 -ftree-pre -o test main.c stuff.c $ ./test 1 1 1 b[0] = 0 1 1 1 b[0] = 0 Works with gcc version 4.7.2 20121109 (Red Hat 4.7.2-8)