The following code: #include <stdio.h>
int main(int argc, char **argv) { void *v = (void*) 1; int *i = (int*) &v; int intpos; for (intpos = 0; intpos < (sizeof(void*) / sizeof(int)); intpos++) if (i[intpos] == 1) break; printf("intpos = %d\n",intpos); } Produces: intpos = 0 when compiled optimization of -O or less. When compiled with -O2, it produces: intpos = 1 on x86 and: intpos = 2 on x86_64. Latest gcc tested is gcc version 4.1.0 20060512 (Red Hat 4.1.0-17) This code is from LAM/MPI. -- Summary: Optimized code gives incorrect result Product: gcc Version: 4.1.0 Status: UNCONFIRMED Severity: major Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: orion at cora dot nwra dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27744