The following code gives wrong result with -O2 and above : % gcc -O0 -o example example.c && ./example 1 % gcc -O2 -o example example.c && ./example 0
The bug is triggered on i486 platform, with gcc 4.3.2 but not with gcc 4.1.2. #include <stdio.h> int main(void) { volatile int y; int x; y = 0x80000000; x = y; if (x < 0) x = -x; printf("%d\n", x == 0x80000000); return 0; } -- Summary: Optimized code gives wrong result Product: gcc Version: 4.3.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: gabriel dot campana at free dot fr GCC build triplet: i486-linux-gnu GCC host triplet: i486-linux-gnu GCC target triplet: i486-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39231