My C program crash if I enable C optimizations -O2 or -fstrict-overflow (-O1 is fine)
I have a C program (hey, I'm cheating here, its generated C code) that crashes (segmentatio开发者_如何学运维n fault) whenever I compile it with gcc -O2
optimization flag. (gcc 4.6.0)
Do you have an idea how I could debug this?
I think I could test by removing the optimizations one by one to see which one makes my program crash ... but this could potentially take a long time. Do you have any better idea?
The optimization that causes the problem is -fstrict-overflow. I'll continue to put new information as I have them.
Thanks
There are some recent reports of compiler issues with that flag (e.g. http://lists.debian.org/debian-gcc/2009/07/msg00168.html) - it would be worth compiling with the latest GCC (or some other compiler if possible) and seeing if that resolves the issue. You could also run with debug symbols, under the debugger if helpful, and see where it crashes. If that surrounding code is clearly bullet proof then that's even more reason to suspect the compiler, otherwise you've somewhere to start your investigations.
精彩评论