http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49873
Summary: Optimizer regression Product: gcc Version: 4.6.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization AssignedTo: unassig...@gcc.gnu.org ReportedBy: abe...@gmail.com Test code: typedef struct { char *ptr; } S; void f1(char* data) { S s; s.ptr = 0; char *same_data = s.ptr + (data - s.ptr); same_data[0] = 1; } int main() { char c; f1(&c); if (c != 1) return 1; return 0; } Compiled with gcc version 4.4.6, the program above returns 0 regardless of the optimization level. Compiled with gcc versions 4.5.3 or 4.6.1, the return value is 0 only with -O0. Using -O1, -O2, -O3 or -Os, the return value is 1. The correct value (0) is returned if s.ptr is replaced with a local variable or the code from the function f1 is moved inside main.