This code: int foo(int arg0) { if ((-2147483647 - 1) + arg0) return 20; else return 11; }
when compiled with gcc-4.4.0 at -O2 or higher, simply returns 20 unconditionally: $ ~/x86-gcc4/bin/gcc -m32 -O2 -S ~/baz.c -o /dev/tty .file "baz.c" .text .p2align 4,,15 .globl foo .type foo, @function foo: pushl %ebp movl $20, %eax movl %esp, %ebp popl %ebp ret .size foo, .-foo .ident "GCC: (GNU) 4.4.0" .section .note.GNU-stack,"",@progbits This bug appears to be architecture-independent (I've seen it on x86, x86_64, and another chip). The bug did not happen in gcc-4.0.2. Here is some information about my system: $ ~/x86-gcc4/bin/gcc --version gcc (GCC) 4.4.0 Copyright (C) 2009 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ uname -a Linux ld-1 2.6.9-42.0.8.ELsmp #1 SMP Tue Jan 30 12:18:01 EST 2007 x86_64 x86_64 x86_64 GNU/Linux $ file bin/gcc bin/gcc: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.4.0, dynamically linked (uses shared libs), not stripped -- Summary: gcc 4.4.0 incorrectly folds add-as-comparison Product: gcc Version: 4.4.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: mat at lcs dot mit dot edu GCC build triplet: x86_64-unknown-linux-gnu GCC host triplet: x86_64-unknown-linux-gnu GCC target triplet: x86_64-unknown-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40189