The -ftrapv doesn't seem to want to generate code that will trap on overflow with optimization. I've tried with and without -fwrapv to try and get it to work. $ cat t.c #include <stdio.h> int foo( int a) { if (a + 100 < a) { printf("Integer overflow detected!\n"); } else { printf("Integer overflow not detected!\n"); } return a; } int main() { foo(0x7fffffff); } mrs2 $ ./xgcc -B./ -fno-wrapv -ftrapv t.c -O2 mrs2 $ a.out Integer overflow detected! mrs2 $ ./xgcc -B./ -fwrapv -ftrapv t.c -O2 mrs2 $ a.out Integer overflow detected! mrs2 $ ./xgcc -B./ -fwrapv -ftrapv t.c mrs2 $ a.out Abort trap mrs2 $ ./xgcc -B./ -fno-wrapv -ftrapv t.c mrs2 $ a.out Abort trap
*** This bug has been marked as a duplicate of 19020 ***