how to make gcc ftrapv work?
c, gcc
Solution
It looks like `-ftrapv` support in GCC is somewhat broken, they have an open bug, Bug-35412 in their Bugzilla from 2008 it seems in order to cover it.
Problem
I am compiling the code below as ``` $ gcc -Wall -ftrapv test.c ``` However running the generated executable always prints-2147483648 which is not what I expected. I am running gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5). ``` 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <limits.h> 4 #include <signal.h> 5 6 void h(int signal) 7 { 8 printf("caught signal exiting\n"); 9 exit(1); 10 } 11 12 int main(void) 13 { 14 int x = INT_MAX; 15 int y; 16 17 signal(SIGABRT,h); 18 y = x+1; 19 printf("%d\n",y); 20 return 0; 21 } ``` Added later: compiling with clang and changing SIGABRT to SIGILL works, but no luck with gcc so far.