Afaik, GCC has some flags for specific types of undefined behavior.
- sign up for the developers' list at http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev ,
- skim over http://clang.llvm.org/hacking.html ,
- build from 'trunk' by carefully following a few simple steps in http://clang.llvm.org/get_started.html ,
- wade in and reproduce your bug ,
... and then share your findings.
Together we can build better tools. Anyone with patience and interest can help.
The only point I wanted to make was that a collective effort might help cut down on ambiguity in expression that the compiler does not identify. I think we could use "more warnings".
Dont code C if you dont know what you are doing.
Also, I'm willing to bet that that if you've written any significant amount of C, you have some undefined behavior that you're not aware of. Just because it works doesn't mean it's defined behavior according to the standard.
I keep wishing that there was a Valgrind-like tool that could detect and report undefined behavior. It would have to be a dynamic, runtime tool, since many/most cases of undefined behavior cannot robustly detected statically. But it would need to have more information at runtime about the original C program than Valgrind has; the assembly alone does not contain enough information to know if the source C program is invoking undefined behavior.
I feel certain that if this tool existed, we would find scores of undefined behavior in all but the most conscientious C programs.