This is for "gcc version 4.3.0 (GCC)" This is similar to bug 35729. I'm filing a new report since the behavior seems to be a different one.
This code: volatile short g_10 = 0; volatile int g_13 = 0; int func_1 (void) { for (g_10 = 0; g_10 > 10; g_10++) return g_13; return 0; } When compiled with: gcc -O1 -S foo.c gives: func_1: pushl %ebp movl %esp, %ebp movw $0, g_10 movzwl g_10, %eax cmpw $10, %ax setle %al movzbl %al, %eax subl $1, %eax andl g_13, %eax popl %ebp ret The output is not correct, it unconditionally returns the value from g_13. -- Summary: wrong code emitted for loop with volatile induction variable Product: gcc Version: 4.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: regehr at cs dot utah dot edu GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35762